-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtaskmap.go
More file actions
52 lines (42 loc) 路 1.11 KB
/
Copy pathtaskmap.go
File metadata and controls
52 lines (42 loc) 路 1.11 KB
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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
// TaskMap struct which contains
// an array of requirements
type TaskMap struct {
Name string `json:"name"`
Requirements []Requirement `json:"requirements"`
}
type Requirement struct {
Name string `json:"name"`
Type string `json:"type"`
Group string `json:"group"`
Satisfiers []Satisfier `json:"satisfiers"`
}
type Satisfier struct {
Uuid string `json:"uuid"`
Count int `json:"count"`
Core []string `json:"core"`
}
func readTaskJSON(fname string) TaskMap {
// Open our jsonFile
jsonFile, err := os.Open(fname)
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
// defer the closing of our jsonFile so that we can parse it later on
defer jsonFile.Close()
// read our opened xmlFile as a byte array.
byteValue, _ := ioutil.ReadAll(jsonFile)
// we initialize our task struct
var task TaskMap
// we unmarshal our byteArray which contains our
// jsonFile's content into 'users' which we defined above
json.Unmarshal(byteValue, &task)
return task
}