add v3
This commit is contained in:
parent
16c053bacb
commit
55f3e2b3c6
9 changed files with 580 additions and 0 deletions
48
v3/config.go
Normal file
48
v3/config.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
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"`
|
||||
SpecialParameters []map[string]interface{} `mapstructure:"special_parameters"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Gradle Gradle
|
||||
Jenkins Jenkins
|
||||
Jobs []string `mapstructure:"jobs"`
|
||||
Retries int `mapstructure:"retries"`
|
||||
}
|
||||
|
||||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue