1
0
Fork 0
mirror of https://github.com/alice-lg/birdwatcher.git synced 2025-03-09 00:00:05 +01:00

Using json.Encoder to write the output JSON instead of using a buffer.

This commit is contained in:
Patrick Seeburger 2019-02-05 17:40:59 +01:00 committed by Benedikt Rudolph
parent e5248b21c7
commit 14a4ebeaaa

View file

@ -73,8 +73,6 @@ func Endpoint(wrapped endpoint) httprouter.Handle {
res[k] = v
}
js, _ := json.Marshal(res)
w.Header().Set("Content-Type", "application/json")
// Check if compression is supported
@ -83,9 +81,11 @@ func Endpoint(wrapped endpoint) httprouter.Handle {
w.Header().Set("Content-Encoding", "gzip")
gz := gzip.NewWriter(w)
defer gz.Close()
gz.Write(js)
json := json.NewEncoder(gz)
json.Encode(res)
} else {
w.Write(js) // Fall back to uncompressed response
json := json.NewEncoder(w)
json.Encode(res) // Fall back to uncompressed response
}
}
}