-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_mutation.go
41 lines (35 loc) · 922 Bytes
/
test_mutation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import "fmt"
import "path/filepath"
import "runtime"
import "encoding/json"
import "io/ioutil"
import "strconv"
import "os"
import "strings"
func main2() {
KnobsPath := "meal_planner/finch_knobs.json"
_, filename, _, _ := runtime.Caller(0)
dir, _ := filepath.Split(filepath.Dir(filename))
file := filepath.Join(dir, KnobsPath)
raw, err := ioutil.ReadFile(file)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
var conf map[string]interface{}
json.Unmarshal(raw, &conf)
for idx, _ := range conf {
s := strconv.FormatFloat(conf[idx].(float64), 'f', 0, 64)
if len(s) == 4 {
newValue, _ := strconv.ParseFloat(strings.TrimSuffix(s, "000"), 64)
conf[idx] = newValue
} else if len(s) == 1 {
extra := "000"
newValue, _ := strconv.ParseFloat(s+string(extra), 64)
conf[idx] = newValue
}
}
newJson, _ := json.Marshal(conf)
err = ioutil.WriteFile(file, newJson, 0644)
}