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

@ -2,7 +2,6 @@ package client
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
@ -49,30 +48,21 @@ type clientConfig struct {
var autorun = flagx.String("autorun", "", "")
type outerconfig struct {
Houston *struct {
Client clientConfig `json:"client"`
} `json:"houston"`
}
func loadClientConfig() (clientConfig, error) {
configFile, err := os.Open("config.json")
if err != nil {
return clientConfig{}, err
}
defer configFile.Close()
var config struct {
Houston *struct {
Client clientConfig `json:"client"`
} `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 clientConfig{}, err
}
if config.Houston == nil {
return clientConfig{}, errors.New(`"houston" object is missing in config.json`)
}
return config.Houston.Client, nil
return oc.Houston.Client, nil
}
type HoustonClient interface {