-
Notifications
You must be signed in to change notification settings - Fork 0
/
spreadsheet2json.go
59 lines (52 loc) · 1.13 KB
/
spreadsheet2json.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"encoding/json"
"fmt"
"log"
"strconv"
)
type data struct {
App string `json:"app"`
Cpu string `json:"cpu"`
Mem string `json:"mem"`
Min int `json:"min"`
Max int `json:"max"`
}
type scale struct {
Data []data `json:"data"`
Nats bool `json:"nats"`
Commit string `json:"commit"`
}
func spreadSheet2Data(sheetdata [][]interface{}) []data {
var allData []data
for i := 0; i < len(sheetdata); i++ {
temp := data{
App: fmt.Sprintf("%v", sheetdata[i][0]),
Cpu: fmt.Sprintf("%v", sheetdata[i][1]),
Mem: fmt.Sprintf("%v", sheetdata[i][2]),
Min: string2Int(fmt.Sprintf("%v", sheetdata[i][3])),
Max: string2Int(fmt.Sprintf("%v", sheetdata[i][4])),
}
allData = append(allData, temp)
}
return allData
}
func string2Int(s string) int {
number, err := strconv.Atoi(s)
if err != nil {
log.Printf("Unable to parse string to int: %v", err)
}
return number
}
func toJson(data []data, nats bool, commit string) ([]byte, error) {
scaledata := scale{
Data: data,
Nats: nats,
Commit: commit,
}
u, err := json.Marshal(scaledata)
if err != nil {
return nil, err
}
return u, nil
}