From 5222454c6c8ccfd94cee281e3bae65f177b6ef9f Mon Sep 17 00:00:00 2001 From: Wendell Sun Date: Sat, 2 Dec 2017 00:27:04 +0800 Subject: [PATCH] Move flag define to main package --- main.go | 6 +++++- utils/conf.go | 11 +++-------- vendor/github.com/go-ignite/ignite/utils/conf.go | 11 +++-------- vendor/vendor.json | 6 +++--- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index 4b32b1a..626cd06 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "flag" + "github.com/gin-gonic/gin" "github.com/go-ignite/ignite-admin/controllers" "github.com/go-ignite/ignite-admin/jobs" @@ -10,8 +12,10 @@ import ( "github.com/robfig/cron" ) +var confPath = flag.String("c", "./conf/config.toml", "config file") + func main() { - utility.InitConf() + utility.InitConf(*confPath) db := utils.InitDB(utility.DB_Driver, utility.DB_Connect) go initRouter(db) go initJob(db) diff --git a/utils/conf.go b/utils/conf.go index 3240597..6c21c12 100644 --- a/utils/conf.go +++ b/utils/conf.go @@ -1,17 +1,12 @@ package utils import ( - "flag" "fmt" "os" toml "github.com/pelletier/go-toml" ) -var ( - confPath = flag.String("c", "./conf/config.toml", "config file") -) - var ( // for app config APP_Address string @@ -23,10 +18,10 @@ var ( Auth_Username, Auth_Password, Auth_Secret string ) -func InitConf() { +func InitConf(confPath string) { //Check config file - if _, err := os.Stat(*confPath); !os.IsNotExist(err) { - if config, err := toml.LoadFile(*confPath); err == nil { + if _, err := os.Stat(confPath); !os.IsNotExist(err) { + if config, err := toml.LoadFile(confPath); err == nil { APP_Address = config.Get("app.address").(string) DB_Driver = config.Get("db.driver").(string) diff --git a/vendor/github.com/go-ignite/ignite/utils/conf.go b/vendor/github.com/go-ignite/ignite/utils/conf.go index 0565542..fec6dd7 100644 --- a/vendor/github.com/go-ignite/ignite/utils/conf.go +++ b/vendor/github.com/go-ignite/ignite/utils/conf.go @@ -1,7 +1,6 @@ package utils import ( - "flag" "fmt" "os" "strconv" @@ -9,10 +8,6 @@ import ( toml "github.com/pelletier/go-toml" ) -var ( - conf = flag.String("c", "./conf/config.toml", "config file") -) - var ( // for app config APP_Address string @@ -28,10 +23,10 @@ var ( HOST_From, HOST_To int ) -func InitConf() { +func InitConf(confPath string) { //Check config file - if _, err := os.Stat(*conf); !os.IsNotExist(err) { - if config, err := toml.LoadFile(*conf); err == nil { + if _, err := os.Stat(confPath); !os.IsNotExist(err) { + if config, err := toml.LoadFile(confPath); err == nil { APP_Address = config.Get("app.address").(string) SS_Image = config.Get("ss.image").(string) diff --git a/vendor/vendor.json b/vendor/vendor.json index f95cc79..c010623 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -289,10 +289,10 @@ "revisionTime": "2017-12-01T14:07:45Z" }, { - "checksumSHA1": "eTnn0UOtxPMk3AqR+HJ0CbYT+hg=", + "checksumSHA1": "1PdlH+bjqdkzObppzHkiBL3FPvk=", "path": "github.com/go-ignite/ignite/utils", - "revision": "5933e18a5f8a4c90b5a5440cbf59bf9f16b3dce2", - "revisionTime": "2017-12-01T14:07:45Z" + "revision": "cb49cb14c11344122d56835302ba20bb79c55357", + "revisionTime": "2017-12-01T16:26:16Z" }, { "checksumSHA1": "QD6LqgLz2JMxXqns8TaxtK9AuHs=",