forked from tangled.org/core
Something went wrong. Try again.
530 B · 22 lines
Go
at master
1234567891011121314151617181920212223package knotserver
import ( "encoding/json" "net/http")
func writeJSON(w http.ResponseWriter, data interface{}) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(data)}
func writeError(w http.ResponseWriter, msg string, status int) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) json.NewEncoder(w).Encode(map[string]string{"error": msg})}
func notFound(w http.ResponseWriter) { writeError(w, "not found", http.StatusNotFound)}