forked from otrack/epaxos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fromfile.go
44 lines (38 loc) · 775 Bytes
/
fromfile.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
package instanceagentmapper
import (
"encoding/json"
"io/ioutil"
"os"
)
type PAM struct { // proposer acceptor mapping
Proposers []int32 `json:"P"`
Acceptors []int32 `json:"A"`
}
//type pams struct {
// pams []PAM `json:""`
//}
func ReadFromFile(loc string) []PAM {
jsonFile, err := os.Open(loc)
defer jsonFile.Close()
if err != nil {
println(err)
}
byteValue, _ := ioutil.ReadAll(jsonFile)
var pam []PAM
json.Unmarshal(byteValue, &pam)
return pam
}
func GetAMap(pam []PAM) [][]int32 {
amap := make([][]int32, 0, len(pam))
for _, m := range pam {
amap = append(amap, m.Acceptors)
}
return amap
}
func GetPMap(pam []PAM) [][]int32 {
pmap := make([][]int32, 0, len(pam))
for _, m := range pam {
pmap = append(pmap, m.Proposers)
}
return pmap
}