Skip to content

Commit

Permalink
fix: vasedb default config path.
Browse files Browse the repository at this point in the history
  • Loading branch information
auula committed Sep 10, 2023
1 parent 2146646 commit b0c119f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*.dll
*.so
*.dylib
./cmd/vasedb
vasedb

# Test binary, built with `go test -c`
*.test
Expand All @@ -18,4 +20,3 @@ testdata

# Dependency directories (remove the comment below to include it)
# vendor/

19 changes: 11 additions & 8 deletions clog/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import (
"github.com/fatih/color"
)

const (
processName = "VASEDB"
)

var (
// Logger colors and log message prefixes
warnColor = color.New(color.Bold, color.FgYellow)
infoColor = color.New(color.Bold, color.FgBlue)
infoColor = color.New(color.Bold, color.FgGreen)
redColor = color.New(color.Bold, color.FgRed)
greenFont = color.New(color.Bold, color.FgGreen)
debugColor = color.New(color.Bold, color.FgHiMagenta)
errorPrefix = redColor.Sprintf("[ERROR] ")
warnPrefix = warnColor.Sprintf("[WARN] ")
Expand All @@ -32,11 +35,11 @@ var (

func init() {
// 总共有两套日志记录器
// [CLASSDB:C] 为主进程记录器记录正常运行状态日志信息
// [CLASSDB:D] 为辅助记录器记录为 Debug 模式下的日志信息
clog = NewLogger(os.Stdout, "[CLASSDB:C] ", log.Ldate|log.Ltime)
// [CLASSDB:D] 只能输出日志信息到标准输出中
dlog = NewLogger(os.Stdout, "[CLASSDB:D] ", log.Ldate|log.Ltime|log.Lshortfile)
// [VASEDB:C] 为主进程记录器记录正常运行状态日志信息
// [VASEDB:D] 为辅助记录器记录为 Debug 模式下的日志信息
clog = NewLogger(os.Stdout, "["+processName+":C] ", log.Ldate|log.Ltime)
// [VASEDB:D] 只能输出日志信息到标准输出中
dlog = NewLogger(os.Stdout, "["+processName+":D] ", log.Ldate|log.Ltime|log.Lshortfile)

}

Expand All @@ -55,7 +58,7 @@ func SetPath(path string) {
Error(err)
}
// 正常模式的日志记录需要输出到控制台和日志文件中
NewColorLogger(io.MultiWriter(os.Stdout, file), "[CLASSDB:C] ", log.Ldate|log.Ltime)
NewColorLogger(io.MultiWriter(os.Stdout, file), "["+processName+":C] ", log.Ldate|log.Ltime)
Info("Initial logger successful")
}

Expand Down
1 change: 1 addition & 0 deletions cmd/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@

VaseDB is a NoSQL that supports multiple data types and transactions.
OPEN SOURCE LICENSE: Apache 2.0 WEBSITE: %s

6 changes: 3 additions & 3 deletions cmd/vasedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func init() {
fl := parseFlags()

// 根据命令行传入的配置文件地址,覆盖掉默认的配置
if fl.config != conf.DefaultPath {
if fl.config != conf.DefaultConfig.FilePath {
if err := conf.Load(fl.config, conf.Settings); err != nil {
clog.Failed(err)
}
Expand Down Expand Up @@ -102,7 +102,7 @@ type flags struct {
func parseFlags() (fl *flags) {
fl = new(flags)
flag.StringVar(&fl.auth, "auth", conf.DefaultConfig.Password, "--auth specify the server authentication password.")
flag.StringVar(&fl.config, "config", conf.DefaultPath, "--config specify the configuration file path.")
flag.StringVar(&fl.config, "config", conf.DefaultConfig.FilePath, "--config specify the configuration file path.")
flag.StringVar(&fl.path, "path", conf.DefaultConfig.Path, "--path specify the data storage directory.")
flag.IntVar(&fl.port, "port", int(conf.DefaultConfig.Port), "--port specify the HTTP server port.")
flag.BoolVar(&fl.debug, "debug", conf.DefaultConfig.Debug, "--debug whether to enable debug mode.")
Expand Down Expand Up @@ -137,8 +137,8 @@ func splitArgs(args []string) []string {
if strings.Contains(args[i], "=") && strings.Count(args[i], "=") == 1 {
newArgs = append(newArgs, strings.Split(args[i], "=")...)
} else {
// 如果是 --port==8080 ,过滤掉 == 不合法过滤掉
if strings.Count(args[i], "=") > 1 {
// 如果是 --port==8080 ,过滤掉 == 不合法过滤掉
continue
}
newArgs = append(newArgs, strings.Split(args[i], "=")...)
Expand Down
11 changes: 6 additions & 5 deletions conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import (
)

const (

// Default configure file format
cfSuffix = "yaml"

DefaultPath = "./config.yaml"
defaultFilePath = "./config.yaml"

// DefaultConfigJSON configure json string
DefaultConfigJSON = `
Expand Down Expand Up @@ -56,6 +54,9 @@ func init() {
clog.Failed(err)
}

// 设置默认的配置文件路径
DefaultConfig.FilePath = defaultFilePath

// 当初始化完成之后应该使用此 Settings 配置
if err := Settings.Unmarshal([]byte(DefaultConfigJSON)); err != nil {
// 读取失败直接退出进程
Expand Down Expand Up @@ -86,8 +87,8 @@ func (opt *ServerConfig) Marshal() ([]byte, error) {
}

type ServerConfig struct {
VaseDB `json:"vasedb"`
ConfigPath string
VaseDB `json:"vasedb"`
FilePath string
}

type VaseDB struct {
Expand Down
6 changes: 3 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type HttpServer struct {
http.Server
shutdown chan struct{}
closed int32
*conf.ServerConfig
Port int32
}

// New 创建一个新的 HTTP 服务器
Expand All @@ -36,8 +36,8 @@ func New(opt *conf.ServerConfig) *HttpServer {
WriteTimeout: 3 * time.Second,
ReadTimeout: 3 * time.Second,
},
ServerConfig: opt,
shutdown: make(chan struct{}),
Port: opt.Port,
shutdown: make(chan struct{}),
}

atomic.StoreInt32(&hs.closed, 0)
Expand Down

0 comments on commit b0c119f

Please sign in to comment.