package 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) } func writeMsg(w http.ResponseWriter, msg string) { writeJSON(w, map[string]string{"msg": msg}) } func writeConflict(w http.ResponseWriter, data interface{}) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusConflict) json.NewEncoder(w).Encode(data) }