// LoadConfigFromEnv will attempt to load a MySQL object // from environment variables. If not populated, nil // is returned. func LoadConfigFromEnv() *Config { var mysql Config config.LoadEnvConfig(&mysql) if mysql.Host != "" { return &mysql } return nil }
// LoadConfigFromEnv will attempt to load an Kafka object // from environment variables. If not populated, nil // is returned. func LoadConfigFromEnv() *Config { var kafka Config config.LoadEnvConfig(&kafka) if kafka.BrokerHostsString == "" { return nil } kafka.BrokerHosts = strings.Split(kafka.BrokerHostsString, ",") return &kafka }
func main() { // showing 1 way of managing gizmo/config: importing from the environment cfg := service.Config{Server: &config.Server{}} config.LoadEnvConfig(&cfg) config.LoadEnvConfig(cfg.Server) server.Init("nyt-simple-proxy", cfg.Server) err := server.Register(service.NewSimpleService(&cfg)) if err != nil { server.Log.Fatal("unable to register service: ", err) } err = server.Run() if err != nil { server.Log.Fatal("server encountered a fatal error: ", err) } }
// LoadBoltDBConfig loads boltdb env and jsonfile config func (b *BoltDB) LoadBoltDBConfig(cfg *AppConfig) { if cfg.ConfigFilePath != "" { config.LoadJSONFile(cfg.ConfigFilePath, b) } config.LoadEnvConfig(b) logrus.Infof("Boltdb database path: %s", cfg.BoltDBPath) logrus.Infof("Boltdb timeout set to: %ds", cfg.BoltDBTimeoutSeconds) }
// LoadConfigFromEnv will attempt to inspect the environment // of any valid config options and will return a populated // Config struct with what it found. // If you need a unique config object and want to use envconfig, you // will need to run the LoadXXFromEnv for each child struct in // your config struct. For an example on how to do this, check out the // guts of this function. func LoadConfigFromEnv() *Config { var app Config config.LoadEnvConfig(&app) app.AWS = aws.LoadConfigFromEnv() app.SNS = awsps.LoadSNSConfigFromEnv() app.SQS = awsps.LoadSQSConfigFromEnv() app.S3 = aws.LoadS3FromEnv() app.DynamoDB = aws.LoadDynamoDBFromEnv() app.ElastiCache = aws.LoadElastiCacheFromEnv() app.MongoDB = mongodb.LoadConfigFromEnv() app.Kafka = kafka.LoadConfigFromEnv() app.MySQL = mysql.LoadConfigFromEnv() app.Oracle = oracle.LoadConfigFromEnv() app.Cookie = cookie.LoadConfigFromEnv() app.Server = server.LoadConfigFromEnv() app.Metrics = metrics.LoadConfigFromEnv() return &app }
// LoadKhronosConfig Loads the configuration for the application func (k *Khronos) LoadKhronosConfig(cfg *AppConfig) { if cfg.ConfigFilePath != "" { config.LoadJSONFile(cfg.ConfigFilePath, k) } config.LoadEnvConfig(k) // Load defaults k.LoadDefaults() // Check storage Engine valid := false for _, v := range ValidStorageEngines { if v == k.StorageEngine { valid = true break } } if !valid { logrus.Fatal("Incorrect storage engine") } logrus.Infof("Using '%s' storage engine", cfg.StorageEngine) logrus.Infof("Set result buffer length to %d", cfg.ResultBufferLen) if k.DontScheduleJobsStart { logrus.Warning("Not loading jobs on startup") } else { logrus.Infof("Loading jobs on startup active") } if k.APIDisableSecurity { logrus.Warning("Security of the API is disabled!") } }
// LoadElastiCacheFromEnv will attempt to load the ElasiCache struct // from environment variables. func LoadElastiCacheFromEnv() ElastiCache { var el ElastiCache config.LoadEnvConfig(&el) return el }
// LoadS3FromEnv will attempt to load the S3 struct // from environment variables. func LoadS3FromEnv() S3 { var s3 S3 config.LoadEnvConfig(&s3) return s3 }
// LoadConfigFromEnv will attempt to load a PubSub config // from environment variables. func LoadConfigFromEnv() Config { var ps Config config.LoadEnvConfig(&ps) return ps }
// LoadConfigFromEnv will attempt to load a GCP config // from environment variables. func LoadConfigFromEnv() Config { var gcp Config config.LoadEnvConfig(&gcp) return gcp }
// LoadConfigFromEnv will attempt to load a Server object // from environment variables. If not populated, nil // is returned. func LoadConfigFromEnv() *Config { var server Config config.LoadEnvConfig(&server) server.Metrics = metrics.LoadConfigFromEnv() return &server }
// LoadConfigFromEnv will attempt to load a Metrics object // from environment variables. func LoadConfigFromEnv() Config { var mets Config config.LoadEnvConfig(&mets) return mets }
// LoadConfigFromEnv will attempt to load an OracleCreds object // from environment variables. func LoadConfigFromEnv() Config { var ora Config config.LoadEnvConfig(&ora) return ora }
func (a *AppConfig) loadConfigFromEnv() { config.LoadEnvConfig(a) config.LoadEnvConfig(a.Server) }
// LoadConfigFromEnv will attempt to load the Config struct // from environment variables. func LoadConfigFromEnv() Config { var aws Config config.LoadEnvConfig(&aws) return aws }
// LoadDynamoDBFromEnv will attempt to load the DynamoDB struct // from environment variables. If not populated, nil // is returned. func LoadDynamoDBFromEnv() DynamoDB { var ddb DynamoDB config.LoadEnvConfig(&ddb) return ddb }
// LoadSNSConfigFromEnv will attempt to load the SNSConfig struct // from environment variables. If not populated, nil // is returned. func LoadSNSConfigFromEnv() SNSConfig { var cfg SNSConfig config.LoadEnvConfig(&cfg) return cfg }
// LoadConfigFromEnv will attempt to load a MongoCreds object // from environment variables. func LoadConfigFromEnv() *Config { var mongo Config config.LoadEnvConfig(&mongo) return &mongo }
// LoadConfigFromEnv will attempt to load an Cookie object // from environment variables. If not populated, nil // is returned. func LoadConfigFromEnv() Config { var cookie Config config.LoadEnvConfig(&cookie) return cookie }