Skip to content

Instantly share code, notes, and snippets.

@eamonnmcevoy
Created April 23, 2017 14:27
Show Gist options
  • Save eamonnmcevoy/de0410163e3386fb4e92cbb7fe123034 to your computer and use it in GitHub Desktop.
Save eamonnmcevoy/de0410163e3386fb4e92cbb7fe123034 to your computer and use it in GitHub Desktop.
package server
import (
"net/http"
"encoding/json"
)
func Error(w http.ResponseWriter, code int, message string) {
Json(w, code, map[string]string{"error": message})
}
func Json(w http.ResponseWriter, code int, payload interface{}) {
response, _ := json.Marshal(payload)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
w.Write(response)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment