Documentation
¶
Overview ¶
Package donewriter provides a simple wrapper around an http.ResponseWriter to track when a response has been sent. To use it, call the WrapWriter middleware early in your middleware stack. Then in other middlewares or handlers, you can use the WriterIsDone method to check the status.
func main() {
r := chi.NewRouter()
r.Use(donewriter.WrapWriter)
// and other middlewares
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
if done, _ := donewriter.WriterIsDone(w); done {
// Nothing to do, a response was already sent
return
}
// Normal operation here...
})
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WrapWriter ¶
WrapWriter is an http middleware which wraps the standard http.ResponseWriter with a DoneWriter. Subsequent middlewares or handlers should use the WriterIsDone method to check the status.
func WriterIsDone ¶
func WriterIsDone(w http.ResponseWriter) (bool, error)
WriterIsDone returns true if a response has been written. An error is returned if the underlying writer is not a DoneWriter.
Types ¶
type DoneWriter ¶
type DoneWriter struct {
http.ResponseWriter
Done bool
}
DoneWriter is an http.ResponseWriter which tracks its write state.
func (*DoneWriter) WriteHeader ¶
func (w *DoneWriter) WriteHeader(status int)
WriteHeader wraps the underlying WriteHeader method.