Files
cybertron/configs/config.go
Varnit Goyal 9b4768c0e6 Tp 55555/integrate document service client (#7)
* TP-55555 | document client and kafka integration

* TP-55555 | introduce service concept refactor code

* TP-55555 | s3 and kafka producer integrated and tested

* TP-55555 | s3 and kafka producer integrated and tested

* TP-55555 | fixed kafka for subsequent request

* TP-55555 | fixed kafka for subsequent request
2024-07-29 15:46:17 +05:30

109 lines
2.0 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
}
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(),
}
}
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
}