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).
Written by Henri LEPIC
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#