Skip to content

Instantly share code, notes, and snippets.

@srfrog
Created August 15, 2014 03:29
Show Gist options
  • Save srfrog/d7f8f5628acf95f158ef to your computer and use it in GitHub Desktop.
Save srfrog/d7f8f5628acf95f158ef to your computer and use it in GitHub Desktop.
func (e *EncoderJSON) Decode(reader io.Reader, v interface{}) error {
r := io.LimitReader(reader, e.MaxBodySize+1)
b, err := ioutil.ReadAll(r)
if err != nil {
return err
}
if int64(len(b)) > e.MaxBodySize {
return ErrBodyTooLarge
}
return json.Unmarshal(b, v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment