mirror of
https://github.com/gogf/gf.git
synced 2025-04-05 11:18:50 +08:00
improve package gcfg
This commit is contained in:
parent
c1b75b9071
commit
6aa39b3451
@ -40,11 +40,15 @@ var (
|
||||
supportedFileTypes = []string{"toml", "yaml", "yml", "json", "ini", "xml"} // All supported file types suffixes.
|
||||
localInstances = gmap.NewStrAnyMap(true) // Instances map containing configuration instances.
|
||||
customConfigContentMap = gmap.NewStrStrMap(true) // Customized configuration content.
|
||||
|
||||
// Prefix array for trying searching in resource manager.
|
||||
resourceTryFiles = []string{
|
||||
"", "/", "config/", "config", "/config", "/config/",
|
||||
"manifest/config/", "manifest/config", "/manifest/config", "/manifest/config/",
|
||||
}
|
||||
|
||||
// Prefix array for trying searching in local system.
|
||||
localSystemTryFiles = []string{"", "config/", "manifest/config"}
|
||||
)
|
||||
|
||||
// NewAdapterFile returns a new configuration management object.
|
||||
|
@ -168,15 +168,18 @@ func (c *AdapterFile) GetFilePath(fileName ...string) (path string, err error) {
|
||||
})
|
||||
}
|
||||
c.autoCheckAndAddMainPkgPathToSearchPaths()
|
||||
// Searching the file system.
|
||||
// Searching local file system.
|
||||
c.searchPaths.RLockFunc(func(array []string) {
|
||||
for _, prefix := range array {
|
||||
prefix = gstr.TrimRight(prefix, `\/`)
|
||||
if path, _ = gspath.Search(prefix, usedFileName); path != "" {
|
||||
return
|
||||
}
|
||||
if path, _ = gspath.Search(prefix+gfile.Separator+"config", usedFileName); path != "" {
|
||||
return
|
||||
for _, tryFile := range localSystemTryFiles {
|
||||
relativePath := gstr.TrimRight(
|
||||
gfile.Join(tryFile, usedFileName),
|
||||
`\/`,
|
||||
)
|
||||
if path, _ = gspath.Search(prefix, relativePath); path != "" {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -192,12 +195,13 @@ func (c *AdapterFile) GetFilePath(fileName ...string) (path string, err error) {
|
||||
))
|
||||
c.searchPaths.RLockFunc(func(array []string) {
|
||||
index := 1
|
||||
for _, v := range array {
|
||||
v = gstr.TrimRight(v, `\/`)
|
||||
buffer.WriteString(fmt.Sprintf("\n%d. %s", index, v))
|
||||
index++
|
||||
buffer.WriteString(fmt.Sprintf("\n%d. %s", index, v+gfile.Separator+"config"))
|
||||
index++
|
||||
for _, prefix := range array {
|
||||
prefix = gstr.TrimRight(prefix, `\/`)
|
||||
for _, tryFile := range localSystemTryFiles {
|
||||
prefixPath := gfile.Join(prefix, tryFile)
|
||||
buffer.WriteString(fmt.Sprintf("\n%d. %s", index, prefixPath))
|
||||
index++
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
@ -205,7 +205,7 @@ func (sp *SPath) Search(name string, indexFiles ...string) (filePath string, isD
|
||||
name = ""
|
||||
}
|
||||
for _, file := range indexFiles {
|
||||
if v := sp.cache.Get(name + "/" + file); v != "" {
|
||||
if v = sp.cache.Get(name + "/" + file); v != "" {
|
||||
return sp.parseCacheValue(v)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user