helpers.go 385 B

1234567891011121314151617
  1. package server
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. )
  6. func setJsonHeader(w http.ResponseWriter, httpStatusCode int) {
  7. w.Header().Set("Content-Type", "application/json")
  8. w.WriteHeader(httpStatusCode)
  9. }
  10. func jsonResponse(w http.ResponseWriter, resp interface{}, httpStatusCode int) {
  11. setJsonHeader(w, httpStatusCode)
  12. jsonResp, _ := json.Marshal(resp)
  13. _, _ = w.Write(jsonResp)
  14. }