func ErrorHandleMaybe(
	w http.ResponseWriter, req *http.Request,
	users interface {
		GetAuthenticated(context.Context) (users.User, error)
	},
	maybeHandler func(w http.ResponseWriter, req *http.Request) error,
) (ok bool) {
	if users == nil {
		users = noUsers{}
	}
	rw := &headerResponseWriter{ResponseWriter: w, Flusher: w.(http.Flusher)}
	err := maybeHandler(rw, req)
	if err == httperror.NotHandle {
		if rw.WroteHeader {
			panic(fmt.Errorf("internal error: maybe handler wrote HTTP header and then returned httperror.NotHandle"))
		}
		return false
	}
	handleError(w, req, err, users, rw.WroteHeader)
	return true
}
ErrorHandleMaybe factors error handling out of the HTTP maybe handler.
If users is nil, it treats all requests as made by an unauthenticated user.
package httputil
import (
	"compress/gzip"
	"context"
	"encoding/json"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"github.com/shurcooL/httperror"
	"github.com/shurcooL/users"
	"golang.org/x/net/http/httpguts"
)
func ErrorHandler(
	users interface {
		GetAuthenticated(context.Context) (users.User, error)
	},
	handler func(w http.ResponseWriter, req *http.Request) error,
) http.Handler {
	if users == nil {
		users = noUsers{}
	}
	return &errorHandler{handler: handler, users: users}
}
type errorHandler struct {
	handler func(w http.ResponseWriter, req *http.Request) error
	users   interface {
		GetAuthenticated(context.Context) (users.User, error)
	}
}
func (h *errorHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	rw := &headerResponseWriter{ResponseWriter: w, Flusher: w.(http.Flusher)}
	err := h.handler(rw, req)
	handleError(w, req, err, h.users, rw.WroteHeader)
}