config 구조 변경
This commit is contained in:
@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
@ -34,8 +33,30 @@ type clientConfig struct {
|
||||
HttpAddress string `json:"http_server_address"`
|
||||
}
|
||||
|
||||
type totalConfig struct {
|
||||
Client clientConfig `json:"houston_client"`
|
||||
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)
|
||||
if err != nil {
|
||||
return clientConfig{}, err
|
||||
}
|
||||
|
||||
if config.Houston == nil {
|
||||
return clientConfig{}, errors.New(`"houston" object is missing in config.json`)
|
||||
}
|
||||
|
||||
return config.Houston.Client, nil
|
||||
}
|
||||
|
||||
type HoustonClient interface {
|
||||
@ -161,28 +182,24 @@ func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryReque
|
||||
}
|
||||
|
||||
func NewClient() (HoustonClient, error) {
|
||||
bt, err := os.ReadFile("config.json")
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return nil, err
|
||||
}
|
||||
var config totalConfig
|
||||
if err := json.Unmarshal(bt, &config); err != nil {
|
||||
clientConfig, err := loadClientConfig()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(config.Client.GrpcAddress) == 0 {
|
||||
if len(clientConfig.GrpcAddress) == 0 {
|
||||
return nil, errors.New("client.grpc_server_address is missing")
|
||||
}
|
||||
|
||||
if len(config.Client.HttpAddress) == 0 {
|
||||
if len(clientConfig.HttpAddress) == 0 {
|
||||
return nil, errors.New("client.http_server_address is missing")
|
||||
}
|
||||
|
||||
var client *grpc.ClientConn
|
||||
for {
|
||||
logger.Println("grpc.DialContext :", config.Client.GrpcAddress)
|
||||
logger.Println("grpc.DialContext :", clientConfig.GrpcAddress)
|
||||
dialContext, cancelDial := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
client, err = grpc.DialContext(dialContext, config.Client.GrpcAddress, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
client, err = grpc.DialContext(dialContext, clientConfig.GrpcAddress, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err == nil {
|
||||
cancelDial()
|
||||
break
|
||||
@ -220,7 +237,7 @@ func NewClient() (HoustonClient, error) {
|
||||
client: client,
|
||||
extraMetrics: unsafe.Pointer(&map[string]float32{}),
|
||||
deploys: deploys,
|
||||
httpAddr: config.Client.HttpAddress,
|
||||
httpAddr: clientConfig.HttpAddress,
|
||||
timestamp: exefi.ModTime().String(),
|
||||
}
|
||||
|
||||
@ -267,6 +284,7 @@ func NewClient() (HoustonClient, error) {
|
||||
var dr shared.DeployRequest
|
||||
unmarshal(&dr, resp.Args)
|
||||
|
||||
logger.Println(dr.Name, myname)
|
||||
if dr.Name == myname {
|
||||
if srcdir, replacer, err := hc.prepareUpdateSelf(&dr); err == nil {
|
||||
args := []string{
|
||||
|
||||
Reference in New Issue
Block a user