133 lines
2.8 KiB
Go
133 lines
2.8 KiB
Go
package configs
|
|
|
|
import (
|
|
"cybertron/pkg/log"
|
|
"strings"
|
|
|
|
"github.com/spf13/viper"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type AppConfig struct {
|
|
name string
|
|
env string
|
|
port int
|
|
metricsPort int
|
|
prometheus *Prometheus
|
|
postgres Postgres
|
|
timezone string
|
|
httpConfig *HttpConfig
|
|
clientConfigs *ClientConfigs
|
|
awsConfig *AwsConfig
|
|
KafkaConfig *KafkaConfig
|
|
ElasticConfig *ElasticConfig
|
|
mjolnir *MjolnirClientConfig
|
|
houston *HoustonClientConfig
|
|
JobSchedulerConfig *JobSchedulerConfig
|
|
}
|
|
|
|
type MigConfig struct {
|
|
postgresConfig Postgres
|
|
}
|
|
|
|
var appConfig AppConfig
|
|
|
|
var migrationConfig MigConfig
|
|
|
|
func LoadConfig() {
|
|
readConfig()
|
|
|
|
appConfig = AppConfig{
|
|
name: getString("name", true),
|
|
env: getString("env", true),
|
|
port: getInt("port", true),
|
|
metricsPort: getInt("metrics.port", true),
|
|
prometheus: GetPrometheusConfig(),
|
|
postgres: getPostgresConfig(),
|
|
timezone: getString("timezone", true),
|
|
clientConfigs: loadClientConfigs(),
|
|
httpConfig: NewHttpConfig(),
|
|
awsConfig: NewAWSConfig(),
|
|
KafkaConfig: NewKafkaConfig(),
|
|
ElasticConfig: NewElasticConfig(),
|
|
mjolnir: NewMjolnirConfig(),
|
|
houston: NewHoustonConfig(),
|
|
JobSchedulerConfig: NewJobSchedulerConfig(),
|
|
}
|
|
}
|
|
|
|
func LoadMigConfig() {
|
|
readConfig()
|
|
|
|
migrationConfig = MigConfig{postgresConfig: getPostgresConfig()}
|
|
}
|
|
func GetAppName() string {
|
|
return appConfig.name
|
|
}
|
|
|
|
func GetEnv() string {
|
|
return appConfig.env
|
|
}
|
|
|
|
func GetMetricsPort() int {
|
|
return appConfig.metricsPort
|
|
}
|
|
|
|
func GetPort() int {
|
|
return appConfig.port
|
|
}
|
|
|
|
func GetPostgresConfig() Postgres {
|
|
return appConfig.postgres
|
|
}
|
|
|
|
func GetPostgresMigConfig() Postgres {
|
|
return migrationConfig.postgresConfig
|
|
}
|
|
|
|
func GetTimezone() *string {
|
|
return &appConfig.timezone
|
|
}
|
|
|
|
func GetAWSConfig() *AwsConfig {
|
|
return appConfig.awsConfig
|
|
}
|
|
|
|
func readConfig() {
|
|
viper.AutomaticEnv()
|
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
|
viper.SetConfigName("config")
|
|
viper.SetConfigType("yaml")
|
|
viper.SetConfigFile("./configs/application.yml")
|
|
|
|
err := viper.ReadInConfig()
|
|
|
|
if err != nil {
|
|
log.Log.GetLog().Panic("Error while loading configuration", zap.Error(err))
|
|
}
|
|
}
|
|
|
|
func GetHttpConfig() *HttpConfig {
|
|
return appConfig.httpConfig
|
|
}
|
|
|
|
func GetKafkaConfig() *KafkaConfig {
|
|
return appConfig.KafkaConfig
|
|
}
|
|
|
|
func GetElasticConfig() *ElasticConfig {
|
|
return appConfig.ElasticConfig
|
|
}
|
|
|
|
func GetMjolnirConfig() *MjolnirClientConfig {
|
|
return appConfig.mjolnir
|
|
}
|
|
|
|
func GetHoustonConfig() *HoustonClientConfig {
|
|
return appConfig.houston
|
|
}
|
|
|
|
func GetJobSchedulerConfig() *JobSchedulerConfig {
|
|
return appConfig.JobSchedulerConfig
|
|
}
|