unlock on error and named arrays for config

This commit is contained in:
2021-04-11 17:02:34 +02:00
parent 8a1fe41825
commit 6e25b90915
14 changed files with 138 additions and 49 deletions

View File

@@ -15,8 +15,8 @@ import (
const VERSION = "1.0.0"
type Config struct {
Locations map[string]Location `mapstructure:"locations"`
Backends map[string]Backend `mapstructure:"backends"`
Locations []Location `mapstructure:"locations"`
Backends []Backend `mapstructure:"backends"`
}
var once sync.Once
@@ -65,12 +65,12 @@ func (c Config) CheckConfig() error {
func GetAllOrSelected(cmd *cobra.Command, backends bool) ([]string, error) {
var list []string
if backends {
for key := range config.Backends {
list = append(list, key)
for _, b := range config.Backends {
list = append(list, b.Name)
}
} else {
for key := range config.Locations {
list = append(list, key)
for _, l := range config.Locations {
list = append(list, l.Name)
}
}
all, _ := cmd.Flags().GetBool("all")