package api import ( "encoding/json" "net/http" ) type Answer struct { Success bool `json:"success"` Id string `json:"id,omitempty"` } func Reply(w http.ResponseWriter, code int, answer Answer) { a, _ := json.Marshal(answer) w.Header().Set(http.CanonicalHeaderKey("content-type"), "application/json") w.WriteHeader(code) w.Write(a) }