package main import ( "log" "github.com/spf13/viper" ) type Gradle struct { Caches []string `mapstructure:"caches"` } type Jenkins struct { Schema string `mapstructure:"schema"` URL string `mapstructure:"url"` User string `mapstructure:"user"` Token string `mapstructure:"token"` Number string `mapstructure:"number"` DefaultParameters []map[string]interface{} `mapstructure:"default_parameters"` } type Config struct { Gradle Gradle Jenkins Jenkins Jobs []string `mapstructure:"jobs"` } func LoadConfig(path string) (*Config, error) { v := viper.New() v.SetConfigName("config") v.SetConfigType("yaml") v.AddConfigPath(path) if err := v.ReadInConfig(); err != nil { log.Fatal("[config] Error reading config file:", err) return nil, err } var config Config if err := v.Unmarshal(&config); err != nil { log.Fatal("[config] Unable to decode config into struct:", err) return nil, err } return &config, nil }