diff --git a/other/httpErr.go b/other/httpErr.go new file mode 100644 index 0000000..ce8b2b1 --- /dev/null +++ b/other/httpErr.go @@ -0,0 +1,23 @@ +package other + +import ( + "encoding/json" + "fmt" + "net/http" +) + +func HttpErr(w http.ResponseWriter, errId int, message string, code int) error { + type errStruct struct { + Id int `json:"id"` + Message string `json:"message"` + } + + data, err := json.Marshal(errStruct{errId, message}) + if err != nil { + return err + } + w.WriteHeader(code) + w.Header().Add("Content-Type", "application/json") + fmt.Fprint(w, data) + return nil +}