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:
parent
e5248b21c7
commit
14a4ebeaaa
1 changed files with 4 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue