Revert "feat: fix config"

This reverts commit c69c5b5cd7.
This commit is contained in:
Roi Feng
2025-05-12 18:45:45 -04:00
parent d80b49045b
commit 8b7d8fe91c
7 changed files with 70 additions and 122 deletions

19
main.go
View File

@ -1,7 +1,6 @@
package main
import (
_ "embed"
"flag"
"log"
"os"
@ -16,9 +15,6 @@ import (
"time"
)
//go:embed config/default.yaml
var defaultConfigContent []byte
func main() {
var basePath string
flag.StringVar(&basePath, "prefix", "", "Config file base path")
@ -29,18 +25,21 @@ func main() {
}
// Load MainConfig
config.InitConfig(defaultConfigContent)
cfg, err := config.LoadMainConfig(basePath)
if err != nil {
log.Fatalf("Load config failed: %v", err)
}
// Load rules
ruleSet, err := config.LoadRules(config.Cfg.Server.RulePath)
ruleSet, err := config.LoadRules(cfg.RulePath)
if err != nil {
log.Fatalf("Load rules failed: %v", err)
}
log.Printf("Ready to start server on port %s", config.Cfg.Server.Port)
log.Printf("Ready to start server on port %s", cfg.Port)
//set log file
defaultLogPath := filepath.Join(config.Cfg.Server.LogPath + "server_torii.log")
defaultLogPath := filepath.Join(cfg.LogPath + "server_torii.log")
logFile, err := os.OpenFile(defaultLogPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("Failed to open log file: %v", err)
@ -53,7 +52,7 @@ func main() {
}(logFile)
log.SetOutput(logFile)
utils.InitLogx(config.Cfg.Server.LogPath)
utils.InitLogx(cfg.LogPath)
//allocate shared memory
sharedMem := &dataType.SharedMemory{
@ -72,7 +71,7 @@ func main() {
serverErr := make(chan error, 1)
go func() {
serverErr <- server.StartServer(ruleSet, sharedMem)
serverErr <- server.StartServer(cfg, ruleSet, sharedMem)
}()
select {