forked from tangled.org/core
Something went wrong. Try again.
815 B · 32 lines
Go
at fix-env-test
123456789101112131415161718192021222324252627282930313233package 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)}