Last Updated: November 16, 2017
·
11.57K
· henripic

Gzip make a light JSON

You could save up to ten times in terms of loading & size when you compress a JSON struct.

func JsonGetHandler(w http.ResponseWriter, r *http.Request) {
 // create header
 w.Header().Add("Accept-Charset", "utf-8")
 w.Header().Add("Content-Type", "application/json")
 w.Header().Set("Content-Encoding", "gzip")
 // Gzip data
 gz := gzip.NewWriter(w)
 json.NewEncoder(gz).Encode(data)
 gz.Close()
}

(In this last exemple you replace data to your struct).