mirror of
https://gitee.com/johng/gf
synced 2026-06-06 02:25:47 +08:00
improve package gcfg for automatically checking and adding path of package main
This commit is contained in:
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user