Closed YashPatel50 closed 1 year ago
Yes there is a much better way, by using interface{}
.
Please provide me with a way to replicate the problem so I can fix it.
Sure here is the code snippet from my current project:
`func GetStaticTraceRouteData(measurementID string, startTime, endTime int) ([]measurement.Result, error) {
a := ripeatlas.Atlaser(ripeatlas.NewHttp())
channel, err := a.MeasurementResults(ripeatlas.Params{"pk": measurementID, "start": startTime, "stop": endTime})
if err != nil {
log.Printf("Cannot get measurment results from Ripe Atlas Streaming API: %v\n", err)
}
var traceroutes []measurement.Result
for measurementTraceroute := range channel {
if measurementTraceroute.ParseError != nil {
log.Printf("Measurement could not be parsed: %v\n", measurementTraceroute.ParseError)
log.Printf("%+v", measurementTraceroute)
} else {
traceroutes = append(traceroutes, *measurementTraceroute)
}
}
return traceroutes, nil`
And I call the function with:
actualTraceRoute, _ := tracerouteData.GetStaticTraceRouteData("5001", 1666915200, 1667001599)
Fixed by #26
Ever since Version 6610 of Traceroute data, the reply result of a hop has err to be either a string or integer.
Case: Reply "err" -- (optional) error ICMP: "N" (network unreachable,), "H" (destination unreachable), "A" (administratively prohibited), "P" (protocol unreachable), "p" (port unreachable) "h" (beyond scope, from fw 4650) (string) Unrecognized error codes are represented as integers
While using this library on the REST API, I encountered a Parsing error on that exact attribute because it was given a number instead of a string.
To combat this, I created a type ErrWrapper that is of type string. I set the Err attribute to type ErrWrapper. I made a custom UnMarshal Method on this type to convert it to a string. Let me know if there is a more elegant solution.