Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
RPiAwesomeness
@RPiAwesomeness
My current code:
func (s UserResource) FindOne(ID string, r api2go.Request) (api2go.Responder, error) {
    log.Debug(ID)
    user, err := s.UserStorage.GetOne(ID)
    var emptyRes []string
    if err == rethink.ErrEmptyResult {
        return &Response{Res: emptyRes, Code: 404}, nil
    } else if err != nil {
        log.Error(err)
        return &Response{}, api2go.NewHTTPError(err, err.Error(), http.StatusInternalServerError)
    }

    marshalled, _ := json.Marshal(user)
    result := model.User{}
    err = json.Unmarshal(marshalled, &result)
    if err != nil {
        // TODO: Add stuff to handle errors
        log.Error(err)
    }

    return &Response{Res: result}, nil
}
Nino
@sharpner
have a look at https://github.com/manyminds/api2go/blob/master/examples/resource/resource_user.go#L122 that's how you currently can implement it. But it seems strange that there are two places to where you can change the statusCode - I'll look into it later
RPiAwesomeness
@RPiAwesomeness
@sharpner That's what I had previously, but since it's not really an error (just that that specific resource doesn't exist) I want to be able to return an empty list under the data key and set the code to 404.
Nino
@sharpner
if you return status code 404 it's actually an error, more appropriate would probably be an empty list and StatusOK because the requested url exists, but does not contain any data
Ben Bieker
@wwwdata
@RPiAwesomeness yes the current behaviour is that data from your resource is only returned for 2xx status codes and all other status codes are error and should return an error. In the jsonapi spec they always mention to return an error object when something fails which makes sense. Either you get what you want or something fails and you get an error.
RPiAwesomeness
@RPiAwesomeness
That makes sense :) :thumbsup:
RPiAwesomeness
@RPiAwesomeness
Is it possible to change the default logger for api2go?
I'm using Sirupsen/logrus and having the occasional api2go, non-logrus logging is a little annoying
Not a requirement, but would be nice
Justin Phelps
@Linuturk
hey guys. I'm still having problem with manyminds/api2go#292 and was hoping I could figure it out in chat
../vendor/github.com/manyminds/api2go/routing/httprouter.go:51:26: cannot use notAllowedHandler (type http.Handler) as type http.HandlerFunc in assignment: need type assertion specifically
and thanks for the patience on this. It seems like a really weird problem
Justin Phelps
@Linuturk
here's a snippet of my main.go where I'm attempting to setup the handler
Justin Phelps
@Linuturk
maybe this belongs in the adapter channel given the gorillamux complication
Justin Phelps
@Linuturk
I've ripped out all the gorilla mux stuff at this point. I've updated the gist with a much simpler version of my main.go
Justin Phelps
@Linuturk
I've reopened my question so I can followup there instead of waiting for chat
Nino
@sharpner
glad you figured it out :) just ask if you have further questions
Justin Phelps
@Linuturk
what's the right way to generate the uuid of a struct if one isn't provided in the Create?
in the POST data
do I implement that in SetID ?
or in the Create method?
Justin Phelps
@Linuturk
so, I implemented it in SetID and it seems to be working as expected. I hope that's the right way to go about it
now I'm struggling to figure out how I determine when I generated a uuid, and when the client provided one, in the context of the struct's Create() method. You are supposed to return different status codes when you generate a uuid vs when the client provided uuid was used.
Nino
@sharpner
good morning! Maybe have a look at the tests which somewhat illustrate how to return custom status codes: https://github.com/manyminds/api2go/blob/b893b9448d075a17008d94413004e337705bb212/api_interfaces_test.go#L36
Justin Phelps
@Linuturk
yeah, totally get how to return custom status codes
that's not really what I was asking
it looks like, based on how the test is laid out, I should be generating the UUID as part of the Create method instead of the SetID method
is that right?
Justin Phelps
@Linuturk
those test cases aren't really an accurate representation of potential id entries btw :-P
Justin Phelps
@Linuturk
so, I figured it out :)
my SetID validation was too strong
and was returning an error when given an ID of ""
so, I just stopped returning an error in that case, and handled the validation in the Create method, which let me set a bool on whether or not it was changed
and then return the proper response
Nino
@sharpner
great ^^" sorry if my initial response was not helpful
Justin Phelps
@Linuturk
@sharpner no worries. You pointed me in the right direction and helped me figure it out
Thanks!
Justin Phelps
@Linuturk
my struct has a field typed []byte, and I'm providing it with a base64 encoded string. It looks like something is decoding that base64 string in api2go
I'm POSTing something with a base64 string, but when I type assert the obj in my Create() method and access the struct field, the base64 is already decoded
is that just api2go magic?
Nino
@sharpner
can you provide an isolated test? I see no way for api2go to decode the base64 data, as there is no way of knowing that some field contains base64
Alfonso de la Osa
@botverse
Hi here
I was wondering if this channel is still active
I'd like some help with some issues
Nino
@sharpner
sure! How can we help? :)
Joel Rebello
@joelrebel
hey guys, do you have any thoughts on generating an OpenAPI schema from an existing api2go implementation
I do realize not everything in JSONAPI is supported by OpenAPI as yet
Simeon Mugisha
@cmeon
Hi guys, i am trying to figure out how to make a resource that returns the user profile with by using the auth token... any thoughts?