ant0ine / go-json-rest

A quick and easy way to setup a RESTful JSON API
https://ant0ine.github.io/go-json-rest/
MIT License
3.51k stars 381 forks source link

float in get params #210

Open kunkhmer opened 7 years ago

kunkhmer commented 7 years ago

Im having a problem passing a float in .GET with params. Is there any solution for this problem? Any double will return "resource not found"

kunkhmer commented 7 years ago

I just ended up using .Post

antitoine commented 7 years ago

The documentation isn't very clear on how to get query parameters, but see #104

I succeed to get a float from query parameter:

func GetRecord(w rest.ResponseWriter, req *rest.Request) {
    if req.URL.Query().Get("startDate") != "" {
        if startDate, err := strconv.ParseFloat(req.URL.Query().Get("startDate"), 64); err == nil && startDate > 0 {
            // do somethings
        } else if err != nil {
            // do somethings
        }
    }
    // do somethings
}