|
|
@@ -3,59 +3,60 @@ package config
|
|
|
import "fmt"
|
|
|
|
|
|
type ApiConfig struct {
|
|
|
- RunMode string
|
|
|
- HttpPort int64
|
|
|
- LogMode string
|
|
|
- AppName string
|
|
|
+ RunMode string
|
|
|
+ HttpPort int64
|
|
|
+ LogMode string
|
|
|
+ AppName string
|
|
|
DataSource string
|
|
|
+ SyncDb bool
|
|
|
}
|
|
|
|
|
|
var AppConfig ApiConfig
|
|
|
-var _config *Config =nil
|
|
|
+var _config *Config = nil
|
|
|
|
|
|
-func init() {
|
|
|
+func init() {
|
|
|
ParseConfig()
|
|
|
}
|
|
|
|
|
|
-func ParseConfig() {
|
|
|
+func ParseConfig() {
|
|
|
var err error
|
|
|
_config, err = LoadConfiguration("conf/app.conf")
|
|
|
- if err != nil{
|
|
|
+ if err != nil {
|
|
|
fmt.Println(err.Error())
|
|
|
AppConfig.AppName = ""
|
|
|
AppConfig.HttpPort = 8080
|
|
|
AppConfig.LogMode = "debug"
|
|
|
AppConfig.RunMode = "debug"
|
|
|
AppConfig.DataSource = ""
|
|
|
- }else{
|
|
|
- AppConfig.AppName = _config.String("appname","")
|
|
|
+ AppConfig.SyncDb = true
|
|
|
+ } else {
|
|
|
+ AppConfig.AppName = _config.String("appname", "")
|
|
|
AppConfig.HttpPort = _config.Integer("httpport", 8080)
|
|
|
AppConfig.LogMode = _config.String("logmode", "debug")
|
|
|
AppConfig.RunMode = _config.String("runmode", "debug")
|
|
|
AppConfig.DataSource = _config.String("datasource", "")
|
|
|
+ AppConfig.SyncDb = _config.Boolean("syncDb", true)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
-func (c *ApiConfig)GetKey(key string) string{
|
|
|
- if _config == nil{
|
|
|
+func (c *ApiConfig) GetKey(key string) string {
|
|
|
+ if _config == nil {
|
|
|
ParseConfig()
|
|
|
}
|
|
|
- return _config.String(key,"")
|
|
|
+ return _config.String(key, "")
|
|
|
}
|
|
|
|
|
|
-func (c *ApiConfig)GetInt(key string) int64 {
|
|
|
- if _config == nil{
|
|
|
+func (c *ApiConfig) GetInt(key string) int64 {
|
|
|
+ if _config == nil {
|
|
|
ParseConfig()
|
|
|
}
|
|
|
- return _config.Integer(key, 0)
|
|
|
+ return _config.Integer(key, 0)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-func (c *ApiConfig)GetBool(key string, def bool) bool {
|
|
|
- if _config == nil{
|
|
|
+func (c *ApiConfig) GetBool(key string, def bool) bool {
|
|
|
+ if _config == nil {
|
|
|
ParseConfig()
|
|
|
}
|
|
|
- return _config.Boolean(key, def)
|
|
|
-}
|
|
|
+ return _config.Boolean(key, def)
|
|
|
+}
|