houston server config에 storagepath 추가
This commit is contained in:
@ -21,7 +21,8 @@ type HoustonServer interface {
|
||||
}
|
||||
|
||||
type serverConfig struct {
|
||||
GrpcPort int `json:"grpc_port"`
|
||||
GrpcPort int `json:"grpc_port"`
|
||||
StoragePath string `json:"storage_path"`
|
||||
}
|
||||
|
||||
type totalConfig struct {
|
||||
@ -110,17 +111,27 @@ type Operation interface {
|
||||
Hosts() map[string]hostSnapshot
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
func loadConfig() serverConfig {
|
||||
var config totalConfig
|
||||
|
||||
config.Server.GrpcPort = 8080
|
||||
configFile, err := os.Open("config.json")
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return config.Server
|
||||
}
|
||||
defer configFile.Close()
|
||||
dec := json.NewDecoder(configFile)
|
||||
err = dec.Decode(&config)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return config.Server
|
||||
}
|
||||
|
||||
return config.Server
|
||||
}
|
||||
|
||||
func NewServer() HoustonServer {
|
||||
var opts []grpc.ServerOption
|
||||
grpcServer := grpc.NewServer(opts...)
|
||||
|
||||
@ -133,7 +144,7 @@ func NewServer() HoustonServer {
|
||||
rpcServer: grpcServer,
|
||||
os: os,
|
||||
ms: ms,
|
||||
port: port,
|
||||
port: loadConfig().GrpcPort,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user