Skip to content

Commit 5bccaa6

Browse files
committed
tmp
1 parent f4ab500 commit 5bccaa6

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

internal/config/config.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path/filepath"
99
"reflect"
10+
"strconv"
1011
"strings"
1112
)
1213

@@ -128,7 +129,7 @@ func set(name, key, value string) error {
128129
content = []byte("{}")
129130
}
130131

131-
var config map[string]map[string]string
132+
var config map[string]map[string]interface{}
132133
if err := json.Unmarshal(content, &config); err != nil {
133134
return err
134135
}
@@ -137,12 +138,25 @@ func set(name, key, value string) error {
137138
return errors.New("invalid key")
138139
} else {
139140
if _, ok := config[splitted[0]]; !ok {
140-
config[splitted[0]] = make(map[string]string, 0)
141+
config[splitted[0]] = make(map[string]interface{}, 0)
141142
}
142143
if strings.TrimSpace(value) == "" {
143144
delete(config[splitted[0]], splitted[1])
144145
} else {
145-
config[splitted[0]][splitted[1]] = value
146+
switch reflect.TypeOf(config[splitted[0]][splitted[1]]).Kind() {
147+
case reflect.Int:
148+
intValue, err := strconv.Atoi(value)
149+
if err != nil {
150+
return err
151+
}
152+
config[splitted[0]][splitted[1]] = intValue
153+
154+
case reflect.String:
155+
config[splitted[0]][splitted[1]] = value
156+
157+
case reflect.Slice:
158+
// TODO
159+
}
146160
}
147161
}
148162

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

155169
return nil
156-
}
170+
}

0 commit comments

Comments
 (0)