34 lines
883 B
Go
34 lines
883 B
Go
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
|
|
package configloaders
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
|
"github.com/TeaOSLab/EdgeUser/internal/rpc"
|
|
)
|
|
|
|
// LoadServerConfig 加载服务配置
|
|
func LoadServerConfig() (*userconfigs.UserServerConfig, error) {
|
|
rpcClient, err := rpc.SharedRPC()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp, err := rpcClient.SysSettingRPC().ReadSysSetting(rpcClient.Context(0), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeUserServerConfig})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var config = userconfigs.DefaultUserServerConfig()
|
|
if len(resp.ValueJSON) > 0 {
|
|
err = json.Unmarshal(resp.ValueJSON, config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return config, nil
|
|
}
|