diff --git a/global/conf.go b/global/conf.go new file mode 100644 index 00000000..44663237 --- /dev/null +++ b/global/conf.go @@ -0,0 +1,3 @@ +package global + +var conf map[string]interface{} diff --git a/pkg/conf/conf.go b/pkg/conf/conf.go index 6ade75f4..8480cf66 100644 --- a/pkg/conf/conf.go +++ b/pkg/conf/conf.go @@ -2,6 +2,7 @@ package conf import ( "github.com/cloudreve/Cloudreve/v3/pkg/util" + "github.com/cloudreve/Cloudreve/v3/global" "github.com/go-ini/ini" "gopkg.in/go-playground/validator.v9" ) @@ -148,6 +149,7 @@ func Init(path string) { util.Log() } + global.conf := sections } // mapSection 将配置文件的 Section 映射到结构体上 diff --git a/pkg/util/path.go b/pkg/util/path.go index 28006968..16137bf0 100644 --- a/pkg/util/path.go +++ b/pkg/util/path.go @@ -5,7 +5,7 @@ import ( "path" "path/filepath" "strings" - "github.com/cloudreve/Cloudreve/v3/pkg/conf" + "github.com/cloudreve/Cloudreve/v3/global" ) // DotPathToStandardPath 将","分割的路径转换为标准路径 @@ -63,8 +63,9 @@ func RelativePath(name string) string { if filepath.IsAbs(name) { return name } - if conf.SystemConfig.DataPath != "" { - return filepath.Join(conf.SystemConfig.DataPath, name) + SystemConfig, ok := global.conf[ "SystemConfig" ] + if SystemConfig.DataPath != "" { + return filepath.Join(SystemConfig.DataPath, name) } else { return RelativeExecutablePath(name) }