config 로딩을 gocommon사용하도록 변경
This commit is contained in:
@ -2,7 +2,6 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@ -49,30 +48,21 @@ type clientConfig struct {
|
|||||||
|
|
||||||
var autorun = flagx.String("autorun", "", "")
|
var autorun = flagx.String("autorun", "", "")
|
||||||
|
|
||||||
func loadClientConfig() (clientConfig, error) {
|
type outerconfig struct {
|
||||||
configFile, err := os.Open("config.json")
|
|
||||||
if err != nil {
|
|
||||||
return clientConfig{}, err
|
|
||||||
}
|
|
||||||
defer configFile.Close()
|
|
||||||
|
|
||||||
var config struct {
|
|
||||||
Houston *struct {
|
Houston *struct {
|
||||||
Client clientConfig `json:"client"`
|
Client clientConfig `json:"client"`
|
||||||
} `json:"houston"`
|
} `json:"houston"`
|
||||||
}
|
}
|
||||||
|
|
||||||
dec := json.NewDecoder(configFile)
|
func loadClientConfig() (clientConfig, error) {
|
||||||
err = dec.Decode(&config)
|
var oc outerconfig
|
||||||
|
err := gocommon.LoadConfig[outerconfig](&oc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Println(err)
|
||||||
return clientConfig{}, err
|
return clientConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Houston == nil {
|
return oc.Houston.Client, nil
|
||||||
return clientConfig{}, errors.New(`"houston" object is missing in config.json`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return config.Houston.Client, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type HoustonClient interface {
|
type HoustonClient interface {
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
|
||||||
|
|
||||||
|
"repositories.action2quare.com/ayo/gocommon"
|
||||||
"repositories.action2quare.com/ayo/gocommon/logger"
|
"repositories.action2quare.com/ayo/gocommon/logger"
|
||||||
"repositories.action2quare.com/ayo/houston/shared"
|
"repositories.action2quare.com/ayo/houston/shared"
|
||||||
"repositories.action2quare.com/ayo/houston/shared/protos"
|
"repositories.action2quare.com/ayo/houston/shared/protos"
|
||||||
@ -108,24 +107,15 @@ type Operation interface {
|
|||||||
DeplyingProgress() []deployingProgress
|
DeplyingProgress() []deployingProgress
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadServerConfig() serverConfig {
|
type outerconfig struct {
|
||||||
configFile, err := os.Open("config.json")
|
|
||||||
if err != nil {
|
|
||||||
logger.Println(err)
|
|
||||||
return serverConfig{
|
|
||||||
GrpcPort: 8080,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
defer configFile.Close()
|
|
||||||
|
|
||||||
var config struct {
|
|
||||||
Houston *struct {
|
Houston *struct {
|
||||||
Server serverConfig `json:"server"`
|
Server serverConfig `json:"server"`
|
||||||
} `json:"houston"`
|
} `json:"houston"`
|
||||||
}
|
}
|
||||||
|
|
||||||
dec := json.NewDecoder(configFile)
|
func loadServerConfig() serverConfig {
|
||||||
err = dec.Decode(&config)
|
var oc outerconfig
|
||||||
|
err := gocommon.LoadConfig[outerconfig](&oc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Println(err)
|
logger.Println(err)
|
||||||
return serverConfig{
|
return serverConfig{
|
||||||
@ -133,14 +123,7 @@ func loadServerConfig() serverConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Houston == nil {
|
return oc.Houston.Server
|
||||||
logger.Println(`"houston" object is missing in config.json`)
|
|
||||||
return serverConfig{
|
|
||||||
GrpcPort: 8080,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return config.Houston.Server
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer() HoustonServer {
|
func NewServer() HoustonServer {
|
||||||
|
|||||||
Reference in New Issue
Block a user