Skip to content

Instantly share code, notes, and snippets.

@zhu327
Created July 28, 2019 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhu327/a17211641740468096808bd215e7a6d0 to your computer and use it in GitHub Desktop.
Save zhu327/a17211641740468096808bd215e7a6d0 to your computer and use it in GitHub Desktop.
func (s *server) respond(w http.ResponseWriter, r *http.Request, data interface{}, status int) {
w.WriteHeader(status)
if data != nil {
err := json.NewEncoder(w).Encode(data)
s.logf("json encode %s", err)
}
}
func (s *server) decode(w http.ResponseWriter, r *http.Request, v interface{}) error {
return json.NewDecoder(r.Body).Decode(v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment