diff --git a/os/gcfg/gcfg.go b/os/gcfg/gcfg.go index 1cd6a7d25..76f5f7985 100644 --- a/os/gcfg/gcfg.go +++ b/os/gcfg/gcfg.go @@ -15,6 +15,7 @@ import ( "github.com/gogf/gf/internal/intlog" "github.com/gogf/gf/os/gcmd" "github.com/gogf/gf/text/gstr" + "github.com/gogf/gf/util/gmode" "github.com/gogf/gf/os/gres" @@ -290,6 +291,7 @@ func (c *Config) GetFilePath(file ...string) (path string, err error) { } }) } + c.autoCheckAndAddMainPkgPathToSearchPaths() // Searching the file system. c.searchPaths.RLockFunc(func(array []string) { for _, prefix := range array { @@ -327,6 +329,19 @@ func (c *Config) GetFilePath(file ...string) (path string, err error) { return } +// autoCheckAndAddMainPkgPathToSearchPaths automatically checks and adds directory path of package main +// to the searching path list if it's currently in development environment. +func (c *Config) autoCheckAndAddMainPkgPathToSearchPaths() { + if gmode.IsDevelop() { + mainPkgPath := gfile.MainPkgPath() + if mainPkgPath != "" { + if !c.searchPaths.Contains(mainPkgPath) { + c.searchPaths.Append(mainPkgPath) + } + } + } +} + // getJson returns a *gjson.Json object for the specified `file` content. // It would print error if file reading fails. It return nil if any error occurs. func (c *Config) getJson(file ...string) *gjson.Json {