Skip to content

Commit

Permalink
add early return to LoadGraphFromJson function if the json file doesn…
Browse files Browse the repository at this point in the history
…'t exist
  • Loading branch information
songtao committed Jun 10, 2021
1 parent 378ea99 commit 309a156
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions metrics/apls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,21 @@ func LoadGraphFromJson(filename string) *graph{
g.loc2index = make(map[string]int)
g.neighbors = make(map[int]map[int]bool)

jsonFile, _ := os.Open(filename)
jsonFile, err := os.Open(filename)
if err != nil {
panic(err)
}
defer jsonFile.Close()

byteValue, err := ioutil.ReadAll(jsonFile)

if err != nil {
fmt.Println(err)
panic(err)
}

var rawresult []interface{}
json.Unmarshal([]byte(byteValue), &rawresult)

nodes := rawresult[0].([]interface{})
edges := rawresult[1].([]interface{})

Expand Down

0 comments on commit 309a156

Please sign in to comment.