From d1038c6764c41a49c1217b654a5dccb4087b3514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=B8=85=E4=BD=A0=E6=8A=A5=E8=AD=A6?= Date: Sat, 30 Oct 2021 20:28:05 +0800 Subject: [PATCH] ddd --- global/conf.go | 3 +++ pkg/conf/conf.go | 2 ++ pkg/util/path.go | 7 ++++--- 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 global/conf.go 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) }