From 49255544f26cb40f5251533ce464cccd4993e147 Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 26 Sep 2018 16:53:06 +0200 Subject: [PATCH] now it compiles, at least --- .gitignore | 1 + go.mod | 2 +- main.go | 20 ++++++++++++-------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 22d0d82..152a7d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ vendor +panel diff --git a/go.mod b/go.mod index 4f3bd1b..e9ef530 100644 --- a/go.mod +++ b/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 ) diff --git a/main.go b/main.go index 02fd958..f44a9e6 100644 --- a/main.go +++ b/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) }