Skip to content

Commit

Permalink
feat: add latency flag (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuhito committed Feb 23, 2023
1 parent 59cc8d1 commit 212dc98
Show file tree
Hide file tree
Showing 13 changed files with 721 additions and 68 deletions.
20 changes: 19 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ func PostAPI(measurement model.PostMeasurement) (model.PostResponse, bool, error
return data, false, nil
}

func DecodeTimings(cmd string, timings json.RawMessage) (model.Timings, error) {
var data model.Timings

if cmd == "ping" {
err := json.Unmarshal(timings, &data.Arr)
if err != nil {
return model.Timings{}, errors.New("invalid timings format returned (ping)")
}
} else {
err := json.Unmarshal(timings, &data.Interface)
if err != nil {
return model.Timings{}, errors.New("invalid timings format returned (other)")
}
}

return data, nil
}

// Get measurement from Globalping API
func GetAPI(id string) (model.GetMeasurement, error) {
// Create a new request
Expand Down Expand Up @@ -114,7 +132,7 @@ func GetAPI(id string) (model.GetMeasurement, error) {
var data model.GetMeasurement
err = json.NewDecoder(resp.Body).Decode(&data)
if err != nil {
return model.GetMeasurement{}, errors.New("err: invalid get measurement format returned")
return model.GetMeasurement{}, errors.New("invalid get measurement format returned")
}

return data, nil
Expand Down

0 comments on commit 212dc98

Please sign in to comment.