Monorepo for Tangled
at bdba60b2c25c9aefb3ab02b46f9e264b16af9495 22 lines 530 B view raw
1package knotserver 2 3import ( 4 "encoding/json" 5 "net/http" 6) 7 8func writeJSON(w http.ResponseWriter, data interface{}) { 9 w.Header().Set("Content-Type", "application/json") 10 w.WriteHeader(http.StatusOK) 11 json.NewEncoder(w).Encode(data) 12} 13 14func writeError(w http.ResponseWriter, msg string, status int) { 15 w.Header().Set("Content-Type", "application/json") 16 w.WriteHeader(status) 17 json.NewEncoder(w).Encode(map[string]string{"error": msg}) 18} 19 20func notFound(w http.ResponseWriter) { 21 writeError(w, "not found", http.StatusNotFound) 22}