package handler import ( "encoding/json" "net/http" ) type Response struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data"` } func SendSuccess(w http.ResponseWriter, data interface{}) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(Response{ Code: 200, Message: "success", Data: data, }) } func SendError(w http.ResponseWriter, httpStatus int, bizCode int, message string) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(httpStatus) json.NewEncoder(w).Encode(Response{ Code: bizCode, Message: message, Data: nil, }) }