forked from boyska/feedpanel
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
|
vendor
|
||||||
|
panel
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -7,6 +7,6 @@ require (
|
||||||
github.com/onsi/gomega v1.4.2 // indirect
|
github.com/onsi/gomega v1.4.2 // indirect
|
||||||
github.com/pkg/errors v0.8.0
|
github.com/pkg/errors v0.8.0
|
||||||
github.com/vmihailenco/sasl v0.0.0-20180913092844-58bfd2104008 // indirect
|
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
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/go-pg/pg"
|
"github.com/go-pg/pg"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -12,11 +13,12 @@ type DB struct {
|
||||||
Schema string
|
Schema string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup(db *DB) error {
|
func (db *DB) Setup() error {
|
||||||
_, err := db.PgDB.Exec(`CREATE SCHEMA IF NOT EXISTS users`)
|
_, err := db.PgDB.Exec(`CREATE SCHEMA IF NOT EXISTS users`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Error creating schema")
|
return errors.Wrap(err, "Error creating schema")
|
||||||
}
|
}
|
||||||
|
fmt.Println("schema created")
|
||||||
|
|
||||||
_, err = db.PgDB.Exec(`CREATE TABLE IF NOT EXISTS users.users (
|
_, err = db.PgDB.Exec(`CREATE TABLE IF NOT EXISTS users.users (
|
||||||
uid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
uid UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||||
|
@ -27,10 +29,11 @@ func Setup(db *DB) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Error creating users table")
|
return errors.Wrap(err, "Error creating users table")
|
||||||
}
|
}
|
||||||
|
fmt.Println("table created")
|
||||||
return nil
|
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)")
|
stmt, err := db.PgDB.Prepare("INSERT INTO users.users VALUES ($1, $2, $3)")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Bad statement in UserAdd")
|
panic("Bad statement in UserAdd")
|
||||||
|
@ -43,16 +46,17 @@ func UserAdd(db *DB, username, email, pwhash string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("vim-go")
|
pgdb := pg.Connect(&pg.Options{
|
||||||
pgdb, err := pg.Connect(&pg.Options{
|
|
||||||
User: "panel",
|
User: "panel",
|
||||||
Password: "",
|
Password: "panelpass",
|
||||||
Database: "feeds",
|
Database: "feeds",
|
||||||
})
|
})
|
||||||
|
db := DB{PgDB: pgdb}
|
||||||
|
err := db.Setup()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
db := DB{PgDB: db}
|
fmt.Println("All done")
|
||||||
db.Setup()
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue