All checks were successful
Auth & User Management Service CI / build-services (app/auth_service/Dockerfile, auth_service, auth_service) (push) Successful in 40s
Auth & User Management Service CI / build-services (app/douyin_ecpm_calculation_service/Dockerfile, douyin_ecpm_calculation_service, douyin_ecpm_calculation_service) (push) Successful in 38s
Auth & User Management Service CI / build-services (app/ranking_management/Dockerfile, ranking_management, ranking_management) (push) Successful in 42s
Auth & User Management Service CI / build-services (app/user_management/Dockerfile, user_manager, user_management) (push) Successful in 39s
Auth & User Management Service CI / start-services (push) Successful in 4s
59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"github.com/spf13/viper"
|
|
_ "github.com/spf13/viper/remote"
|
|
"github.com/zeromicro/go-zero/zrpc"
|
|
)
|
|
|
|
const (
|
|
TypeKey = "CONFIG_TYPE" // 配置文件类型
|
|
TypeEtcd = "etcd"
|
|
TypeEnv = "env"
|
|
|
|
EtcdPrefix = "/youtu/"
|
|
EtcdAddrKey = "ETCD_ADDR"
|
|
)
|
|
|
|
type Redis struct {
|
|
Host string `json:"host"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
type AppAccount struct {
|
|
AppId string `json:"appId"`
|
|
Secret string `json:"secret"`
|
|
Type string `json:"type"`
|
|
}
|
|
|
|
type Config struct {
|
|
RpcServerConf zrpc.RpcServerConf
|
|
Mode string
|
|
Mysql string
|
|
Redis []Redis
|
|
}
|
|
|
|
func init() {
|
|
viper.SetDefault(EtcdAddrKey, "192.168.0.47:2379")
|
|
viper.SetDefault(TypeKey, TypeEtcd)
|
|
}
|
|
|
|
func GetConfig(c *Config, serverName string) (err error) {
|
|
err = viper.AddRemoteProvider("etcd3", viper.GetString(EtcdAddrKey), EtcdPrefix+serverName+".rpc")
|
|
if err != nil {
|
|
return
|
|
}
|
|
viper.SetConfigType("json") // because there is no file extension in a stream of bytes, supported extensions are "json", "toml", "yaml", "yml", "properties", "props", "prop", "env", "dotenv"
|
|
err = viper.ReadRemoteConfig()
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = viper.Unmarshal(&c)
|
|
if err != nil {
|
|
return
|
|
}
|
|
c.RpcServerConf.Name = serverName + ".rpc"
|
|
c.RpcServerConf.ServiceConf.Mode = c.Mode
|
|
return
|
|
}
|