-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A entry in /hosts can span multiple runs due to start and endrun not being the same.
- Loading branch information
Showing
2 changed files
with
39 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,39 @@ | ||
package gdq | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
type host struct { | ||
Handle string `json:"handle"` | ||
Runs []uint `json:"runs"` | ||
} | ||
|
||
type hostResp struct { | ||
Fields struct { | ||
Run uint `json:"start_run"` | ||
Handle string `json:"name"` | ||
StartRun uint `json:"start_run"` | ||
EndRun uint `json:"end_run"` | ||
Handle string `json:"name"` | ||
} `json:"fields"` | ||
} | ||
|
||
type hostsResp []hostResp | ||
func (h *host) UnmarshalJSON(b []byte) error { | ||
var v hostResp | ||
if err := json.Unmarshal(b, &v); err != nil { | ||
return err | ||
} | ||
|
||
h.Handle = v.Fields.Handle | ||
|
||
if v.Fields.StartRun == v.Fields.EndRun { | ||
h.Runs = []uint{v.Fields.StartRun} | ||
} else { | ||
seq := make([]uint, v.Fields.EndRun-v.Fields.StartRun+1) | ||
for i := range seq { | ||
seq[i] = v.Fields.StartRun + uint(i) | ||
} | ||
h.Runs = seq | ||
} | ||
|
||
return nil | ||
} |