From 64f3acca2641f53e4c031b62cbc3bbf73ea0da73 Mon Sep 17 00:00:00 2001 From: ZhengYang Date: Wed, 13 Aug 2014 14:34:12 +0800 Subject: [PATCH] loading driver and connStr from json if there is no commandline options specified --- bee.json | 6 +++++- conf.go | 10 +++++++++- migrate.go | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/bee.json b/bee.json index 0c0ee71..41dced8 100644 --- a/bee.json +++ b/bee.json @@ -13,5 +13,9 @@ "others": [] }, "cmd_args": [], - "envs": [] + "envs": [], + "database": { + "driver": "mysql", + "conn": "root:@tcp(127.0.0.1:3306)/test" + } } \ No newline at end of file diff --git a/conf.go b/conf.go index 0561c0d..5a116b5 100644 --- a/conf.go +++ b/conf.go @@ -36,7 +36,11 @@ var defaultConf = `{ "others": [] }, "cmd_args": [], - "envs": [] + "envs": [], + "database": { + "driver": "mysql", + "conn": "root:@tcp(127.0.0.1:3306)/test" + } } ` var conf struct { @@ -62,6 +66,10 @@ var conf struct { Dirs []string IngExt []string `json:"ignore_ext"` } + Database struct { + Driver string + Conn string + } } // loadConfig loads customized configuration. diff --git a/migrate.go b/migrate.go index a644aad..610d895 100644 --- a/migrate.go +++ b/migrate.go @@ -70,15 +70,26 @@ func runMigration(cmd *Command, args []string) { ColorLog("[HINT] Set $GOPATH in your environment vairables\n") os.Exit(2) } + // load config + err := loadConfig() + if err != nil { + ColorLog("[ERRO] Fail to parse bee.json[ %s ]\n", err) + } // getting command line arguments if len(args) != 0 { cmd.Flag.Parse(args[1:]) } if mDriver == "" { - mDriver = "mysql" + mDriver = docValue(conf.Database.Driver) + if mDriver == "" { + mDriver = "mysql" + } } if mConn == "" { - mConn = "root:@tcp(127.0.0.1:3306)/test" + mConn = docValue(conf.Database.Conn) + if mConn == "" { + mConn = "root:@tcp(127.0.0.1:3306)/test" + } } ColorLog("[INFO] Using '%s' as 'driver'\n", mDriver) ColorLog("[INFO] Using '%s' as 'conn'\n", mConn)