now it compiles, at least
This commit is contained in:
parent
47cf67c735
commit
49255544f2
3 changed files with 14 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
vendor
|
||||
panel
|
||||
|
|
2
go.mod
2
go.mod
|
@ -7,6 +7,6 @@ require (
|
|||
github.com/onsi/gomega v1.4.2 // indirect
|
||||
github.com/pkg/errors v0.8.0
|
||||
github.com/vmihailenco/sasl v0.0.0-20180913092844-58bfd2104008 // indirect
|
||||
golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||
mellium.im/sasl v0.2.1 // indirect
|
||||
)
|
||||
|
|
20
main.go
20
main.go
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/go-pg/pg"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -12,11 +13,12 @@ type DB struct {
|
|||
Schema string
|
||||
}
|
||||
|
||||
func Setup(db *DB) error {
|
||||
func (db *DB) Setup() error {
|
||||
_, err := db.PgDB.Exec(`CREATE SCHEMA IF NOT EXISTS users`)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Error creating schema")
|
||||
}
|
||||
fmt.Println("schema created")
|
||||
|
||||
_, err = db.PgDB.Exec(`CREATE TABLE IF NOT EXISTS users.users (
|
||||
uid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
|
@ -27,10 +29,11 @@ func Setup(db *DB) error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "Error creating users table")
|
||||
}
|
||||
fmt.Println("table created")
|
||||
return nil
|
||||
}
|
||||
|
||||
func UserAdd(db *DB, username, email, pwhash string) error {
|
||||
func (db *DB) UserAdd(username, email, pwhash string) error {
|
||||
stmt, err := db.PgDB.Prepare("INSERT INTO users.users VALUES ($1, $2, $3)")
|
||||
if err != nil {
|
||||
panic("Bad statement in UserAdd")
|
||||
|
@ -43,16 +46,17 @@ func UserAdd(db *DB, username, email, pwhash string) error {
|
|||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println("vim-go")
|
||||
pgdb, err := pg.Connect(&pg.Options{
|
||||
pgdb := pg.Connect(&pg.Options{
|
||||
User: "panel",
|
||||
Password: "",
|
||||
Password: "panelpass",
|
||||
Database: "feeds",
|
||||
})
|
||||
db := DB{PgDB: pgdb}
|
||||
err := db.Setup()
|
||||
if err != nil {
|
||||
os.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
db := DB{PgDB: db}
|
||||
db.Setup()
|
||||
fmt.Println("All done")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
Reference in a new issue