From b44bd1a38a7128b96bf997238d61ce364b66dcb8 Mon Sep 17 00:00:00 2001 From: Leon Ding Date: Thu, 14 Mar 2024 07:43:30 +0800 Subject: [PATCH] fix: http server port option. fix: http server port option. fix: http server port option. --- cmd/vasedb.go | 21 ++++++++++++--------- conf/config.go | 9 ++++----- vfs/filesys.go | 7 ++++--- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/cmd/vasedb.go b/cmd/vasedb.go index 4db99ac..026fe38 100644 --- a/cmd/vasedb.go +++ b/cmd/vasedb.go @@ -52,13 +52,13 @@ 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) + } + clog.Info("Loading custom config file was successful") } if fl.debug { @@ -81,18 +81,22 @@ func init() { clog.Debug(conf.Settings.ToString()) + var err error = nil + // 设置一下运行过程中日志输出文件的路径 err = clog.SetPath(conf.Settings.LogPath) if err != nil { clog.Failed(err) } - clog.Info("Initial logger successful") + clog.Info("Initial logger setup successful") - err = vfs.SetupFS(conf.Settings.Path) + err = vfs.SetupFS(conf.Settings.Path, conf.Folders...) if err != nil { clog.Failed(err) } + + clog.Info("Setup file system was successful") } // flags 优先级别最高的参数,从命令行传入 @@ -138,7 +142,6 @@ func main() { // 开始执行正常的 vasedb 逻辑,这里会启动 HTTP 服务器让客户端连接 hs, err := server.New(conf.Settings.Port) - if err != nil { clog.Failed(err) } 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 }