DNS-OARC / ripeatlas

Go bindings for RIPE Atlas API
MIT License
11 stars 12 forks source link

Updating Reply data structure #25

Closed YashPatel50 closed 1 year ago

YashPatel50 commented 1 year ago

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.

jelu commented 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.

jelu commented 1 year ago

Or try https://github.com/DNS-OARC/ripeatlas/pull/26 | https://github.com/jelu/ripeatlas/tree/trace-reply-v4610

YashPatel50 commented 1 year ago

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)

jelu commented 1 year ago

Fixed by #26