mirror of
https://github.com/moul/sshportal.git
synced 2025-01-11 01:47:46 +08:00
Add --debug options + mysql driver
This commit is contained in:
parent
33b8000b17
commit
d7e84e615d
2 changed files with 10 additions and 3 deletions
1
db.go
1
db.go
|
@ -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
12
main.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue