diff --git a/frame/gins/gins_database.go b/frame/gins/gins_database.go index 0904d93b2..abd88549a 100644 --- a/frame/gins/gins_database.go +++ b/frame/gins/gins_database.go @@ -25,7 +25,6 @@ const ( // Database returns an instance of database ORM object // with specified configuration group name. func Database(name ...string) gdb.DB { - config := Config() group := gdb.DEFAULT_GROUP_NAME if len(name) > 0 && name[0] != "" { group = name[0] @@ -41,13 +40,12 @@ func Database(name ...string) gdb.DB { return db } var m map[string]interface{} - if _, v := gutil.MapPossibleItemByKey( - config.GetMap("."), - gDATABASE_NODE_NAME, - ); v != nil { - m = gconv.Map(v) + // It firstly searches the configuration of the instance name. + nodeKey, _ := gutil.MapPossibleItemByKey(Config().GetMap("."), gVIEWER_NODE_NAME) + if nodeKey == "" { + nodeKey = gDATABASE_NODE_NAME } - if len(m) == 0 { + if m = Config().GetMap(nodeKey); len(m) == 0 { panic(fmt.Sprintf(`database init failed: "%s" node not found, is config file or configuration missing?`, gDATABASE_NODE_NAME)) } // Parse as map-slice and adds it to gdb's global configurations. @@ -86,18 +84,9 @@ func Database(name ...string) gdb.DB { if db, err := gdb.New(name...); err == nil { // Initialize logger for ORM. var m map[string]interface{} - if _, v := gutil.MapPossibleItemByKey( - config.GetMap("."), - fmt.Sprintf("%s.%s", gDATABASE_NODE_NAME, gLOGGER_NODE_NAME), - ); v != nil { - m = gconv.Map(v) - } else { - if _, v := gutil.MapPossibleItemByKey( - Config().GetMap("."), - gLOGGER_NODE_NAME, - ); v != nil { - m = gconv.Map(v) - } + m = Config().GetMap(fmt.Sprintf("%s.%s", nodeKey, gLOGGER_NODE_NAME)) + if len(m) == 0 { + m = Config().GetMap(nodeKey) } if len(m) > 0 { if err := db.GetLogger().SetConfigWithMap(m); err != nil { diff --git a/frame/gins/gins_log.go b/frame/gins/gins_log.go index 8713c8bd8..887efdf5f 100644 --- a/frame/gins/gins_log.go +++ b/frame/gins/gins_log.go @@ -9,7 +9,6 @@ package gins import ( "fmt" "github.com/gogf/gf/os/glog" - "github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gutil" ) @@ -31,21 +30,13 @@ func Log(name ...string) *glog.Logger { // To avoid file no found error while it's not necessary. if Config().Available() { var m map[string]interface{} - // It firstly searches the configuration of the instance name. - if _, v := gutil.MapPossibleItemByKey( - Config().GetMap("."), - fmt.Sprintf(`%s.%s`, gLOGGER_NODE_NAME, instanceName), - ); v != nil { - m = gconv.Map(v) - } else { - // If the configuration for the instance does not exist, - // it uses the default logging configuration. - if _, v := gutil.MapPossibleItemByKey( - Config().GetMap("."), - gLOGGER_NODE_NAME, - ); v != nil { - m = gconv.Map(v) - } + nodeKey, _ := gutil.MapPossibleItemByKey(Config().GetMap("."), gLOGGER_NODE_NAME) + if nodeKey == "" { + nodeKey = gLOGGER_NODE_NAME + } + m = Config().GetMap(fmt.Sprintf(`%s.%s`, nodeKey, instanceName)) + if len(m) == 0 { + m = Config().GetMap(nodeKey) } if len(m) > 0 { if err := logger.SetConfigWithMap(m); err != nil { diff --git a/frame/gins/gins_server.go b/frame/gins/gins_server.go index c42f9e268..3735578f3 100644 --- a/frame/gins/gins_server.go +++ b/frame/gins/gins_server.go @@ -9,7 +9,6 @@ package gins import ( "fmt" "github.com/gogf/gf/net/ghttp" - "github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gutil" ) @@ -26,21 +25,13 @@ func Server(name ...interface{}) *ghttp.Server { // To avoid file no found error while it's not necessary. if Config().Available() { var m map[string]interface{} - // It firstly searches the configuration of the instance name. - if _, v := gutil.MapPossibleItemByKey( - Config().GetMap("."), - fmt.Sprintf(`%s.%s`, gSERVER_NODE_NAME, s.GetName()), - ); v != nil { - m = gconv.Map(v) - } else { - // If the configuration for the instance does not exist, - // it uses the default server configuration. - if _, v := gutil.MapPossibleItemByKey( - Config().GetMap("."), - gSERVER_NODE_NAME, - ); v != nil { - m = gconv.Map(v) - } + nodeKey, _ := gutil.MapPossibleItemByKey(Config().GetMap("."), gSERVER_NODE_NAME) + if nodeKey == "" { + nodeKey = gSERVER_NODE_NAME + } + m = Config().GetMap(fmt.Sprintf(`%s.%s`, nodeKey, s.GetName())) + if len(m) == 0 { + m = Config().GetMap(nodeKey) } if len(m) > 0 { if err := s.SetConfigWithMap(m); err != nil { diff --git a/frame/gins/gins_view.go b/frame/gins/gins_view.go index 60fae1641..73e09ff82 100644 --- a/frame/gins/gins_view.go +++ b/frame/gins/gins_view.go @@ -9,7 +9,6 @@ package gins import ( "fmt" "github.com/gogf/gf/os/gview" - "github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gutil" ) @@ -40,21 +39,13 @@ func getViewInstance(name ...string) *gview.View { // To avoid file no found error while it's not necessary. if Config().Available() { var m map[string]interface{} - // It firstly searches the configuration of the instance name. - if _, v := gutil.MapPossibleItemByKey( - Config().GetMap("."), - fmt.Sprintf(`%s.%s`, gVIEWER_NODE_NAME, instanceName), - ); v != nil { - m = gconv.Map(v) - } else { - // If the configuration for the instance does not exist, - // it uses the default view configuration. - if _, v := gutil.MapPossibleItemByKey( - Config().GetMap("."), - gVIEWER_NODE_NAME, - ); v != nil { - m = gconv.Map(v) - } + nodeKey, _ := gutil.MapPossibleItemByKey(Config().GetMap("."), gVIEWER_NODE_NAME) + if nodeKey == "" { + nodeKey = gVIEWER_NODE_NAME + } + m = Config().GetMap(fmt.Sprintf(`%s.%s`, nodeKey, instanceName)) + if len(m) == 0 { + m = Config().GetMap(nodeKey) } if len(m) > 0 { if err := view.SetConfigWithMap(m); err != nil {