mirror of
https://github.com/rjNemo/go-microservices-tuto
synced 2026-06-06 02:16:46 +00:00
24 lines
568 B
Go
24 lines
568 B
Go
package handlers
|
|
|
|
import (
|
|
"compress/gzip"
|
|
"net/http"
|
|
)
|
|
|
|
// GZipResponseMiddleware detects if the client can handle zipped content and if
|
|
// so returns the response in GZipped format
|
|
func GZipResponseMiddleware(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|
|
|
|
type WrappedResponseWriter struct {
|
|
w http.ResponseWriter
|
|
g *gzip.Writer
|
|
}
|
|
|
|
func NewWrappedResponseWriter(w http.ResponseWriter) *WrappedResponseWriter {
|
|
g := gzip.NewWriter(w)
|
|
return &WrappedResponseWriter{w, g}
|
|
}
|