Skip to content

Instantly share code, notes, and snippets.

@dennypenta
Created February 5, 2019 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennypenta/b35006683531f17f1fdd72c7640f817b to your computer and use it in GitHub Desktop.
Save dennypenta/b35006683531f17f1fdd72c7640f817b to your computer and use it in GitHub Desktop.
type Model struct {
value []byte
}
func (m *Model) UnmarshalJSON(v []byte) error {
m.value = v
return nil
}
func Map(body io.Reader, v json.Unmarshaler) {
data, _ := ioutil.ReadAll(body)
v.UnmarshalJSON(data)
}
type Controller struct {
mapper func(*http.Request, json.Unmarshaler) error
newModelFunc func() Model
}
func (c *Controller) Bla(r *http.Request) {
model := c.newModelFunc()
_ = c.mapper(r, &model)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment