config 로딩을 gocommon사용하도록 변경
This commit is contained in:
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user