서버, 클라이언트 config 분리

This commit is contained in:
2023-06-09 11:53:31 +09:00
parent cff643310b
commit 1d87ef3501
4 changed files with 73 additions and 10 deletions

View File

@ -1,9 +1,12 @@
package server
import (
"encoding/json"
"fmt"
"net"
"os"
"repositories.action2quare.com/ayo/gocommon/logger"
"repositories.action2quare.com/ayo/houston/shared"
"repositories.action2quare.com/ayo/houston/shared/protos"
@ -12,11 +15,19 @@ import (
// protoc --go_out=. --go-grpc_out=. protos/*.proto
type HoustonServer interface {
Start(port int) error
Start() error
Stop()
Operation() Operation
}
type serverConfig struct {
GrpcPort int `json:"grpc_port"`
}
type totalConfig struct {
Server serverConfig `json:"houston_server"`
}
type DeployRequest struct {
shared.DeployRequest
hostnames []string
@ -100,6 +111,15 @@ type Operation interface {
}
func NewServer() HoustonServer {
port := 8080
if bt, err := os.ReadFile("config.json"); err == nil {
var config totalConfig
if err := json.Unmarshal(bt, &config); err == nil {
if config.Server.GrpcPort == 0 {
port = config.Server.GrpcPort
}
}
}
var opts []grpc.ServerOption
grpcServer := grpc.NewServer(opts...)
@ -113,6 +133,7 @@ func NewServer() HoustonServer {
rpcServer: grpcServer,
os: os,
ms: ms,
port: port,
}
}
@ -120,10 +141,12 @@ type houstonServer struct {
rpcServer *grpc.Server
os *operationServer
ms *monitorServer
port int
}
func (hs *houstonServer) Start(port int) error {
lis, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port))
func (hs *houstonServer) Start() error {
logger.Println("houston server is started at port", hs.port)
lis, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", hs.port))
if err != nil {
return err
}