func (w *gzipResponseWriter) Flush() {
	if !w.wroteHeader {
		w.WriteHeader(http.StatusOK)
	}
	flusher := w.ResponseWriter.(http.Flusher)
	flusher.Flush()
}
Make sure the local WriteHeader is called, and call the parent Flush.
Provided in order to implement the http.Flusher interface.
package rest
import (
	"bufio"
	"compress/gzip"
	"net"
	"net/http"
	"strings"
)
type GzipMiddleware struct{}
func (mw *GzipMiddleware) MiddlewareFunc(h HandlerFunc) HandlerFunc {
	return func(w ResponseWriter, r *Request) {
		canGzip := strings.Contains(r.Header.Get("Accept-Encoding"), "gzip")
		writer := &gzipResponseWriter{w, false, canGzip, nil}
		defer func() {
			if writer.gzipWriter != nil {
				writer.gzipWriter.Close()
			}
		}()
		h(writer, r)
	}
}
type gzipResponseWriter struct {
	ResponseWriter
	wroteHeader bool
	canGzip     bool
	gzipWriter  *gzip.Writer
}
func (w *gzipResponseWriter) WriteHeader(code int) {
	w.Header().Add("Vary", "Accept-Encoding")
	if w.canGzip {
		w.Header().Set("Content-Encoding", "gzip")
	}
	w.ResponseWriter.WriteHeader(code)
	w.wroteHeader = true
}
func (w *gzipResponseWriter) WriteJson(v interface{}) error {
	b, err := w.EncodeJson(v)
	if err != nil {
		return err
	}
	_, err = w.Write(b)
	if err != nil {
		return err
	}
	return nil
}