json_proto_response.go 394 B

12345678910111213141516171819
  1. package ginutil
  2. import (
  3. "kpt-tmr-group/pkg/apierr"
  4. "kpt-tmr-group/pkg/jsonpb"
  5. "net/http"
  6. "github.com/gin-gonic/gin"
  7. "github.com/golang/protobuf/proto"
  8. )
  9. func JSONResp(c *gin.Context, pb proto.Message) {
  10. bs, err := jsonpb.MarshalBytes(pb)
  11. if err != nil {
  12. apierr.AbortInternalError(c, http.StatusInternalServerError, err)
  13. return
  14. }
  15. c.Data(http.StatusOK, "application/json", bs)
  16. }