From f3096a2a1c0ff28702a95a1c907a961a61eb26c4 Mon Sep 17 00:00:00 2001 From: rsteube Date: Mon, 18 Jul 2022 22:09:11 +0200 Subject: [PATCH] tmp --- internal/config/config.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index de7fd8625..098e0cef7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "reflect" + "strconv" "strings" ) @@ -128,7 +129,7 @@ func set(name, key, value string) error { content = []byte("{}") } - var config map[string]map[string]string + var config map[string]map[string]interface{} if err := json.Unmarshal(content, &config); err != nil { return err } @@ -137,12 +138,25 @@ func set(name, key, value string) error { return errors.New("invalid key") } else { if _, ok := config[splitted[0]]; !ok { - config[splitted[0]] = make(map[string]string, 0) + config[splitted[0]] = make(map[string]interface{}, 0) } if strings.TrimSpace(value) == "" { delete(config[splitted[0]], splitted[1]) } else { - config[splitted[0]][splitted[1]] = value + switch reflect.TypeOf(config[splitted[0]][splitted[1]]).Kind() { + case reflect.Int: + intValue, err := strconv.Atoi(value) + if err != nil { + return err + } + config[splitted[0]][splitted[1]] = intValue + + case reflect.String: + config[splitted[0]][splitted[1]] = value + + case reflect.Slice: + // TODO + } } } @@ -153,4 +167,4 @@ func set(name, key, value string) error { os.WriteFile(file, marshalled, os.ModePerm) return nil -} +} \ No newline at end of file