李伟乐 2 years ago
parent 57c959790d
commit caf994906e
  1. 22
      response/response.go

@ -3,7 +3,6 @@ package response
import (
"encoding/json"
"git.diulo.com/mogfee/protoc-gen-kit/xerrors"
"git.diulo.com/mogfee/protoc-gen-kit/xjson"
"git.diulo.com/mogfee/protoc-gen-kit/xstring"
"github.com/gin-gonic/gin"
"github.com/go-playground/form"
@ -64,28 +63,9 @@ type ValidateError interface {
Reason() string
ErrorName() string
}
type MyRender struct {
Data any
}
func (m *MyRender) Render(writer http.ResponseWriter) error {
jsonBytes, err := xjson.Marshal(m.Data)
if err != nil {
return err
}
_, err = writer.Write(jsonBytes)
return err
}
func (m *MyRender) WriteContentType(w http.ResponseWriter) {
header := w.Header()
if val := header["Content-Type"]; len(val) == 0 {
header["Content-Type"] = []string{"application/json; charset=utf-8"}
}
}
func (s *result) Success(data any) {
s.ctx.Render(http.StatusOK, &MyRender{Data: data})
s.ctx.JSON(http.StatusOK, data)
}
func (s *result) Result(httpCode int, reason string, message string, metadata map[string]string) {
s.ctx.JSON(httpCode, gin.H{

Loading…
Cancel
Save