Skip to content

Instantly share code, notes, and snippets.

@srfrog
Created August 15, 2014 03:55
Show Gist options
  • Save srfrog/423a218b72ac656d9076 to your computer and use it in GitHub Desktop.
Save srfrog/423a218b72ac656d9076 to your computer and use it in GitHub Desktop.
func (e *EncoderJSON) Decode(reader io.Reader, v interface{}) error {
// suggested by dsal@IRC
r := &io.LimitedReader{reader, e.MaxBodySize}
err := json.NewDecoder().Decode(v)
if err != nil && r.N == 0 {
return ErrBodyTooLarge
}
return err
}
@srfrog
Copy link
Author

srfrog commented Aug 15, 2014

this is a better version of https://gist.github.com/srfrog/d7f8f5628acf95f158ef
go rid of the dreaded ioutil.ReadAll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment