Add --debug options + mysql driver

This commit is contained in:
Manfred Touron 2017-10-30 17:12:04 +01:00
parent 33b8000b17
commit d7e84e615d
2 changed files with 10 additions and 3 deletions

1
db.go
View file

@ -22,7 +22,6 @@ type User struct {
}
func dbInit(db *gorm.DB) error {
db.LogMode(true)
db.AutoMigrate(&User{})
db.AutoMigrate(&Key{})
db.AutoMigrate(&Host{})

12
main.go
View file

@ -10,6 +10,7 @@ import (
"github.com/gliderlabs/ssh"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/urfave/cli"
)
@ -42,13 +43,17 @@ func main() {
cli.StringFlag{
Name: "db-driver",
Value: "sqlite3",
Usage: "GORM driver (sqlite3, mysql)",
},
cli.StringFlag{
Name: "db-conn",
Value: "./sshportal.db",
Usage: "GORM connection string",
},
cli.BoolFlag{
Name: "debug, D",
Usage: "Display debug information",
},
// TODO: add verbose mode
// TODO: add web server
}
app.Action = server
app.Run(os.Args)
@ -60,6 +65,9 @@ func server(c *cli.Context) error {
return err
}
defer db.Close()
if c.Bool("debug") {
db.LogMode(true)
}
if err := dbInit(db); err != nil {
return err
}