mirror of
https://github.com/beego/bee.git
synced 2024-11-22 10:10:53 +00:00
loading driver and connStr from json if there is no commandline options specified
This commit is contained in:
parent
4775fc3e81
commit
64f3acca26
6
bee.json
6
bee.json
@ -13,5 +13,9 @@
|
|||||||
"others": []
|
"others": []
|
||||||
},
|
},
|
||||||
"cmd_args": [],
|
"cmd_args": [],
|
||||||
"envs": []
|
"envs": [],
|
||||||
|
"database": {
|
||||||
|
"driver": "mysql",
|
||||||
|
"conn": "root:@tcp(127.0.0.1:3306)/test"
|
||||||
|
}
|
||||||
}
|
}
|
10
conf.go
10
conf.go
@ -36,7 +36,11 @@ var defaultConf = `{
|
|||||||
"others": []
|
"others": []
|
||||||
},
|
},
|
||||||
"cmd_args": [],
|
"cmd_args": [],
|
||||||
"envs": []
|
"envs": [],
|
||||||
|
"database": {
|
||||||
|
"driver": "mysql",
|
||||||
|
"conn": "root:@tcp(127.0.0.1:3306)/test"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
var conf struct {
|
var conf struct {
|
||||||
@ -62,6 +66,10 @@ var conf struct {
|
|||||||
Dirs []string
|
Dirs []string
|
||||||
IngExt []string `json:"ignore_ext"`
|
IngExt []string `json:"ignore_ext"`
|
||||||
}
|
}
|
||||||
|
Database struct {
|
||||||
|
Driver string
|
||||||
|
Conn string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadConfig loads customized configuration.
|
// loadConfig loads customized configuration.
|
||||||
|
11
migrate.go
11
migrate.go
@ -70,16 +70,27 @@ func runMigration(cmd *Command, args []string) {
|
|||||||
ColorLog("[HINT] Set $GOPATH in your environment vairables\n")
|
ColorLog("[HINT] Set $GOPATH in your environment vairables\n")
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
// load config
|
||||||
|
err := loadConfig()
|
||||||
|
if err != nil {
|
||||||
|
ColorLog("[ERRO] Fail to parse bee.json[ %s ]\n", err)
|
||||||
|
}
|
||||||
// getting command line arguments
|
// getting command line arguments
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
cmd.Flag.Parse(args[1:])
|
cmd.Flag.Parse(args[1:])
|
||||||
}
|
}
|
||||||
|
if mDriver == "" {
|
||||||
|
mDriver = docValue(conf.Database.Driver)
|
||||||
if mDriver == "" {
|
if mDriver == "" {
|
||||||
mDriver = "mysql"
|
mDriver = "mysql"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if mConn == "" {
|
||||||
|
mConn = docValue(conf.Database.Conn)
|
||||||
if mConn == "" {
|
if mConn == "" {
|
||||||
mConn = "root:@tcp(127.0.0.1:3306)/test"
|
mConn = "root:@tcp(127.0.0.1:3306)/test"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ColorLog("[INFO] Using '%s' as 'driver'\n", mDriver)
|
ColorLog("[INFO] Using '%s' as 'driver'\n", mDriver)
|
||||||
ColorLog("[INFO] Using '%s' as 'conn'\n", mConn)
|
ColorLog("[INFO] Using '%s' as 'conn'\n", mConn)
|
||||||
driverStr, connStr := string(mDriver), string(mConn)
|
driverStr, connStr := string(mDriver), string(mConn)
|
||||||
|
Loading…
Reference in New Issue
Block a user