122 lines
3.9 KiB
Go
122 lines
3.9 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"gitee.com/codinl/erp_server/config/file"
|
|
"gitee.com/codinl/erp_server/config/internal"
|
|
"github.com/codinl/go-logger"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var ConfigValue *configValue
|
|
|
|
// Config 当前service的config
|
|
var Config internal.Config
|
|
|
|
type configValue struct {
|
|
ConfigHost string `json:"config_host"`
|
|
ConfigPort int `json:"config_port"`
|
|
|
|
ServiceHttpPort int `json:"service_http_port"`
|
|
ServiceRpcPort int `json:"service_rpc_port"`
|
|
ServiceHttpsPort int `json:"service_https_port"`
|
|
|
|
MysqlDriver string `json:"mysql_driver"`
|
|
MysqlHost string `json:"mysql_host"`
|
|
MysqlPort string `json:"mysql_port"`
|
|
MysqlUser string `json:"mysql_user"`
|
|
MysqlDBName string `json:"mysql_db_name"`
|
|
MysqlPassword string `json:"mysql_user_password"`
|
|
|
|
RedisHost string `json:"redis_host"`
|
|
RedisPort string `json:"redis_port"`
|
|
RedisUser string `json:"redis_user"`
|
|
RedisPassword string `json:"redis_password"`
|
|
|
|
MongoHost string `json:"mongo_host"`
|
|
MongoPort string `json:"mongo_port"`
|
|
MongoUser string `json:"mongo_user"`
|
|
MongoPassword string `json:"mongo_password"`
|
|
MongoDBName string `json:"mongo_db_name"`
|
|
|
|
AliyunAccessKeyID string `json:"aliyun_access_key_id"`
|
|
AliyunAccessKeySecret string `json:"aliyun_access_key_secret"`
|
|
AliyunRoleArn string `json:"aliyun_role_arn"`
|
|
AliyunOssBaseUrl string `json:"aliyun_oss_base_url"`
|
|
AliyunOssBucketName string `json:"aliyun_oss_bucket_name"`
|
|
AliyunKafkaEndpoint string `json:"aliyun_kafka_endpoint"`
|
|
|
|
JwtKey string `json:"jwt_key"`
|
|
JwtExpire int `json:"jwt_expire"`
|
|
|
|
PaypalClientId string `json:"paypal_client_id"`
|
|
PaypalSecret string `json:"paypal_secret"`
|
|
PaypalAPIBase string `json:"paypal_api_base"`
|
|
|
|
LoggerPath string `json:"logger_path"`
|
|
LoggerFile string `json:"logger_file"`
|
|
LoggerLevel int `json:"logger_level"`
|
|
}
|
|
|
|
func Init(c *cli.Context) error {
|
|
//servicePath := fmt.Sprintf("%s/.app.config.yaml", DefaultConfigPath)
|
|
servicePath := fmt.Sprintf("%s/.app.config.yaml", ".")
|
|
cfg := internal.New(internal.WithSource(
|
|
file.NewSource(servicePath),
|
|
))
|
|
if err := cfg.Load(); err != nil {
|
|
logger.Error("cfg load err:", err)
|
|
return err
|
|
}
|
|
|
|
Config = cfg
|
|
|
|
ConfigValue = &configValue{
|
|
ConfigHost: Config.Value("config.host").String(),
|
|
ConfigPort: int(Config.Value("config.port").Int()),
|
|
|
|
ServiceHttpPort: int(Config.Value("service.http.port").Int()),
|
|
ServiceRpcPort: int(Config.Value("service.rpc.port").Int()),
|
|
ServiceHttpsPort: int(Config.Value("service.https.port").Int()),
|
|
|
|
MysqlDriver: Config.Value("mysql.driver").String(),
|
|
MysqlHost: Config.Value("mysql.host").String(),
|
|
MysqlPort: Config.Value("mysql.port").String(),
|
|
MysqlUser: Config.Value("mysql.user").String(),
|
|
MysqlDBName: Config.Value("mysql.db_name").String(),
|
|
MysqlPassword: Config.Value("mysql.password").String(),
|
|
|
|
RedisHost: Config.Value("redis.host").String(),
|
|
RedisPort: Config.Value("redis.port").String(),
|
|
RedisUser: Config.Value("redis.user").String(),
|
|
RedisPassword: Config.Value("redis.password").String(),
|
|
|
|
MongoHost: Config.Value("mongo.host").String(),
|
|
MongoPort: Config.Value("mongo.port").String(),
|
|
MongoUser: Config.Value("mongo.user").String(),
|
|
MongoPassword: Config.Value("mongo.password").String(),
|
|
MongoDBName: Config.Value("mongo.db_name").String(),
|
|
|
|
AliyunAccessKeyID: "",
|
|
AliyunAccessKeySecret: "",
|
|
AliyunRoleArn: "",
|
|
AliyunOssBaseUrl: "",
|
|
AliyunOssBucketName: "",
|
|
AliyunKafkaEndpoint: "",
|
|
|
|
JwtKey: Config.Value("jwt.key").String(),
|
|
JwtExpire: int(Config.Value("jwt.expire").Int()),
|
|
|
|
PaypalClientId: Config.Value("paypal.client_id").String(),
|
|
PaypalSecret: Config.Value("paypal.secret").String(),
|
|
PaypalAPIBase: Config.Value("paypal.api_base").String(),
|
|
|
|
LoggerPath: Config.Value("logger.path").String(),
|
|
LoggerFile: Config.Value("logger.file").String(),
|
|
LoggerLevel: int(Config.Value("logger.level").Int()),
|
|
}
|
|
|
|
return nil
|
|
}
|