Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marshal an interface #141

Open
abh opened this issue May 23, 2018 · 0 comments
Open

Marshal an interface #141

abh opened this issue May 23, 2018 · 0 comments

Comments

@abh
Copy link

abh commented May 23, 2018

I was looking at converting a small existing system to use jsonapi.

The structure for my response handlers is

type FooResponse interface {
   ID() int
   Foos() FooList
  ...
}

var resp FooResponse

// a bunch of conditional logic that gets FooResponse set

	if err := jsonapi.MarshalPayload(w, resp); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

For the other ways I use FooResponse, this makes a lot of sense. Can I add a method to the FooResponse interface that jsonapi would call to build the response? Glancing through the code nothing stands out, it seems like it'll only work with a "plain" struct or slice directly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant