config 로딩을 gocommon사용하도록 변경

This commit is contained in:
2024-06-06 13:18:50 +09:00
parent fdb534c5e0
commit 95d6741389
2 changed files with 20 additions and 47 deletions

View File

@ -1,11 +1,10 @@
package server
import (
"encoding/json"
"fmt"
"net"
"os"
"repositories.action2quare.com/ayo/gocommon"
"repositories.action2quare.com/ayo/gocommon/logger"
"repositories.action2quare.com/ayo/houston/shared"
"repositories.action2quare.com/ayo/houston/shared/protos"
@ -108,24 +107,15 @@ type Operation interface {
DeplyingProgress() []deployingProgress
}
type outerconfig struct {
Houston *struct {
Server serverConfig `json:"server"`
} `json:"houston"`
}
func loadServerConfig() serverConfig {
configFile, err := os.Open("config.json")
if err != nil {
logger.Println(err)
return serverConfig{
GrpcPort: 8080,
}
}
defer configFile.Close()
var config struct {
Houston *struct {
Server serverConfig `json:"server"`
} `json:"houston"`
}
dec := json.NewDecoder(configFile)
err = dec.Decode(&config)
var oc outerconfig
err := gocommon.LoadConfig[outerconfig](&oc)
if err != nil {
logger.Println(err)
return serverConfig{
@ -133,14 +123,7 @@ func loadServerConfig() serverConfig {
}
}
if config.Houston == nil {
logger.Println(`"houston" object is missing in config.json`)
return serverConfig{
GrpcPort: 8080,
}
}
return config.Houston.Server
return oc.Houston.Server
}
func NewServer() HoustonServer {