Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jul 18, 2022
1 parent a4a6dea commit f3096a2
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"reflect"
"strconv"
"strings"
)

Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
}
}

Expand All @@ -153,4 +167,4 @@ func set(name, key, value string) error {
os.WriteFile(file, marshalled, os.ModePerm)

return nil
}
}

0 comments on commit f3096a2

Please sign in to comment.