Created
August 15, 2014 03:55
-
-
Save srfrog/423a218b72ac656d9076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is a better version of https://gist.github.com/srfrog/d7f8f5628acf95f158ef
go rid of the dreaded ioutil.ReadAll