Skip to content

Instantly share code, notes, and snippets.

@Jxck
Last active November 17, 2022 20:34
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Jxck/4cab517ef113f84aa007 to your computer and use it in GitHub Desktop.
Save Jxck/4cab517ef113f84aa007 to your computer and use it in GitHub Desktop.
gocon 2014
type errWriter struct {
w io.Writer
err error
}
func (e *errWriter) Write(p []byte) {
if e.err != nil {
return
}
_, e.err = e.w.Write(p)
}
func (e *errWriter) Err() error {
return e.err
}
func do() {
ew := &errWriter{w: ...}
ew.Write(buf)
ew.Write(buf)
...
...
if ew.Err() != nil {
return ew.Err()
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment