From b4396c97bb713bd450edb1cf01ced6095fb03755 Mon Sep 17 00:00:00 2001 From: Ming Deng Date: Thu, 5 Nov 2020 22:00:43 +0800 Subject: [PATCH] fix init error of global instance --- core/config/global.go | 12 ------------ core/config/ini.go | 11 ++++++++++- core/logs/log.go | 2 +- server/web/parser.go | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/core/config/global.go b/core/config/global.go index c5c59ba7..5491fe2c 100644 --- a/core/config/global.go +++ b/core/config/global.go @@ -14,22 +14,10 @@ package config -import ( - "github.com/astaxie/beego/core/logs" -) - // We use this to simply application's development // for most users, they only need to use those methods var globalInstance Configer -func init() { - // Ignore this error - err := InitGlobalInstance("ini", "config/app.conf") - if err != nil { - logs.Warn("init global config instance failed. If you donot use this, just ignore it. ", err) - } - -} // InitGlobalInstance will ini the global instance // If you want to use specific implementation, don't forget to import it. diff --git a/core/config/ini.go b/core/config/ini.go index 93dd774a..4d17fb7a 100644 --- a/core/config/ini.go +++ b/core/config/ini.go @@ -29,6 +29,8 @@ import ( "sync" "github.com/mitchellh/mapstructure" + + "github.com/astaxie/beego/core/logs" ) var ( @@ -97,7 +99,7 @@ func (ini *IniConfig) parseData(dir string, data []byte) (*IniConfigContainer, e break } - //It might be a good idea to throw a error on all unknonw errors? + // It might be a good idea to throw a error on all unknonw errors? if _, ok := err.(*os.PathError); ok { return nil, err } @@ -516,4 +518,11 @@ func (c *IniConfigContainer) Unmarshaler(prefix string, obj interface{}, opt ... func init() { Register("ini", &IniConfig{}) + + err := InitGlobalInstance("ini", "config/app.conf") + if err != nil { + logs.Warn("init global config instance failed. If you donot use this, just ignore it. ", err) + } } + +// Ignore this error diff --git a/core/logs/log.go b/core/logs/log.go index b05abd3b..d5953dfb 100644 --- a/core/logs/log.go +++ b/core/logs/log.go @@ -687,7 +687,7 @@ func EnableFuncCallDepth(b bool) { // SetLogFuncCall set the CallDepth, default is 4 func SetLogFuncCall(b bool) { beeLogger.EnableFuncCallDepth(b) - beeLogger.SetLogFuncCallDepth(4) + beeLogger.SetLogFuncCallDepth(3) } // SetLogFuncCallDepth set log funcCallDepth diff --git a/server/web/parser.go b/server/web/parser.go index 820c8b10..c3434501 100644 --- a/server/web/parser.go +++ b/server/web/parser.go @@ -39,7 +39,7 @@ import ( var globalRouterTemplate = `package {{.routersDir}} import ( - "github.com/astaxie/beego" + beego "github.com/astaxie/beego/server/web" "github.com/astaxie/beego/server/web/context/param"{{.globalimport}} )