Skip to content

Commit

Permalink
fix: http server port option.
Browse files Browse the repository at this point in the history
  • Loading branch information
auula committed Mar 14, 2024
1 parent d5e7d75 commit 7738fe4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
20 changes: 11 additions & 9 deletions cmd/vasedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -81,18 +81,21 @@ 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 优先级别最高的参数,从命令行传入
Expand Down Expand Up @@ -138,7 +141,6 @@ func main() {

// 开始执行正常的 vasedb 逻辑,这里会启动 HTTP 服务器让客户端连接
hs, err := server.New(conf.Settings.Port)

if err != nil {
clog.Failed(err)
}
Expand Down
9 changes: 4 additions & 5 deletions conf/config.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// 尽量减少 conf 的配置参数侵入到其他包中
// conf 包只限于 cmd 包下使用
package conf

import (
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions vfs/filesys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -26,6 +26,7 @@ func SetupFS(path string) error {
}
}

clog.Info("Initial storage successful")
// 不要写在这里如果这个包被单独拿出去使用,不能配置 clog 包使用
// clog.Info("Initial storage successful")
return nil
}

0 comments on commit 7738fe4

Please sign in to comment.