func LoadConfigFromEnv() (*GlobalConfig, error) {
	var instance GlobalConfig
	if err := viper.Unmarshal(&instance); err != nil {
		return nil, err
	}
	err := envconfig.Process("", &instance)
	if err != nil {
		return &instance, err
	}
	return &instance, nil
}
LoadConfigFromEnv loads config values from environment variables
package config
import (
	"time"
	"github.com/hellofresh/logging-go"
	"github.com/kelseyhightower/envconfig"
	log "github.com/sirupsen/logrus"
	"github.com/spf13/viper"
)
type GlobalConfig struct {
	RabbitDSN string `envconfig:"RABBIT_DSN"`
	StorageDSN string `envconfig:"STORAGE_DSN"`
	Log logging.LogConfig
	Kafka KafkaConfig
	Stats StatsConfig
	Worker WorkerConfig
}
type KafkaConfig struct {
	Brokers []string `envconfig:"KAFKA_BROKERS"`
	MaxRetry int `envconfig:"KAFKA_MAX_RETRY"`
	PipesConfig string `envconfig:"KAFKA_PIPES_CONFIG"`
}
type StatsConfig struct {
	DSN           string `envconfig:"STATS_DSN"`
	ErrorsSection string `envconfig:"STATS_ERRORS_SECTION"`
}
type WorkerConfig struct {
	CycleTimeout time.Duration `envconfig:"WORKER_CYCLE_TIMEOUT"`
	CacheSize int `envconfig:"WORKER_CACHE_SIZE"`
	CacheFlushTimeout time.Duration `envconfig:"WORKER_CACHE_FLUSH_TIMEOUT"`
	StorageReadTimeout time.Duration `envconfig:"WORKER_STORAGE_READ_TIMEOUT"`
	StorageMaxErrors int `envconfig:"WORKER_STORAGE_MAX_ERRORS"`
}
func init() {
	viper.SetDefault("logLevel", "info")
	viper.SetDefault("kafka.maxRetry", 5)
	viper.SetDefault("kafka.pipesConfig", "/etc/kandalf/conf/pipes.yml")
	viper.SetDefault("worker.cycleTimeout", time.Second*time.Duration(2))
	viper.SetDefault("worker.cacheSize", 10)
	viper.SetDefault("worker.cacheFlushTimeout", time.Second*time.Duration(5))
	viper.SetDefault("worker.storageReadTimeout", time.Second*time.Duration(10))
	viper.SetDefault("worker.storageMaxErrors", 10)
	viper.SetDefault("stats.dsn", "log://")
	viper.SetDefault("stats.errorsSection", "error-log")
	logging.InitDefaults(viper.GetViper(), "log")
}
func Load(configPath string) (*GlobalConfig, error) {
	if configPath != "" {
		viper.SetConfigFile(configPath)
	} else {
		viper.SetConfigName("config")
		viper.AddConfigPath("/etc/kandalf/conf")
		viper.AddConfigPath(".")
	}
	if err := viper.ReadInConfig(); err != nil {
		log.WithError(err).Warn("No config file found, loading config from environment variables")
		return LoadConfigFromEnv()
	}
	log.WithField("path", viper.ConfigFileUsed()).Info("Config loaded from file")
	var instance GlobalConfig
	if err := viper.Unmarshal(&instance); err != nil {
		return nil, err
	}
	return &instance, nil
}