Created
April 23, 2017 14:27
-
-
Save eamonnmcevoy/de0410163e3386fb4e92cbb7fe123034 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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