diff --git a/cmd/vasedb.go b/cmd/vasedb.go index 4db99ac..9243f6f 100644 --- a/cmd/vasedb.go +++ b/cmd/vasedb.go @@ -52,13 +52,12 @@ func init() { // 解析命令行输入的参数,默认命令行参数优先级最高,但是相对于能设置参数比较少 fl := parseFlags() - var err error = nil - // 根据命令行传入的配置文件地址,覆盖掉默认的配置 - err = conf.HasCustomConfig(fl.config) - - if err != nil { - clog.Failed(err) + if conf.HasCustomConfig(fl.config) { + err := conf.Load(fl.config, conf.Settings) + if err != nil { + clog.Failed(err) + } } if fl.debug { @@ -81,6 +80,8 @@ func init() { clog.Debug(conf.Settings.ToString()) + var err error = nil + // 设置一下运行过程中日志输出文件的路径 err = clog.SetPath(conf.Settings.LogPath) if err != nil { @@ -89,10 +90,12 @@ func init() { clog.Info("Initial logger successful") - err = vfs.SetupFS(conf.Settings.Path) + err = vfs.SetupFS(conf.Settings.Path, conf.Folders...) if err != nil { clog.Failed(err) } + + clog.Info("Initial file system successful") } // flags 优先级别最高的参数,从命令行传入 diff --git a/conf/config.go b/conf/config.go index 0e3b2e7..bded5bd 100644 --- a/conf/config.go +++ b/conf/config.go @@ -1,3 +1,5 @@ +// 尽量减少 conf 的配置参数侵入到其他包中 +// conf 包只限于 cmd 包下使用 package conf import ( @@ -63,11 +65,8 @@ func init() { } // HasCustomConfig checked enable custom config -func HasCustomConfig(path string) error { - if path != defaultFilePath { - return Load(path, Settings) - } - return nil +func HasCustomConfig(path string) bool { + return path != defaultFilePath } // Load through a configuration file diff --git a/vfs/filesys.go b/vfs/filesys.go index c61a474..dbcc419 100644 --- a/vfs/filesys.go +++ b/vfs/filesys.go @@ -10,10 +10,10 @@ import ( ) // SetupFS build vasedb file system -func SetupFS(path string) error { +func SetupFS(path string, folders ...string) error { // 拼接文件路径 - for _, dir := range conf.Folders { + for _, dir := range folders { // 检查目录是否存在 if utils.IsExist(filepath.Join(path, dir)) { clog.Infof("Initial %s checked successful", dir) @@ -26,6 +26,7 @@ func SetupFS(path string) error { } } - clog.Info("Initial storage successful") + // 不要写在这里如果这个包被单独拿出去使用,不能配置 clog 包使用 + // clog.Info("Initial storage successful") return nil }