Files
InsightReply/server/internal/handler/common.go
2026-02-28 20:05:15 +08:00

33 lines
696 B
Go

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,
})
}