Files
open-im-server/pkg/common/http/http_resp.go
T

33 lines
640 B
Go
Raw Normal View History

2022-01-21 18:39:57 +08:00
package http
2022-01-24 01:40:49 +08:00
import (
"Open_IM/pkg/common/constant"
2022-01-25 19:18:04 +08:00
//"Open_IM/pkg/cms_api_struct"
2022-01-24 01:40:49 +08:00
"net/http"
"github.com/gin-gonic/gin"
)
type BaseResp struct {
Code int32 `json:"code"`
ErrMsg string `json:"err_msg"`
Data interface{} `json:"data"`
}
2022-01-25 19:18:04 +08:00
func RespHttp200(ctx *gin.Context, err error, data interface{}) {
var resp BaseResp
if v, ok := err.(constant.ErrInfo); ok {
resp.Code = v.Code()
resp.ErrMsg = v.Error()
} else {
resp.Code = constant.ErrServer.Code()
resp.ErrMsg = constant.ErrServer.Error()
2022-01-24 01:40:49 +08:00
}
2022-01-25 19:18:04 +08:00
resp.Data=data
2022-01-24 01:40:49 +08:00
ctx.JSON(http.StatusOK, resp)
}
2022-01-25 19:18:04 +08:00
//func CheckErr(pb interface{}) constant.ErrInfo{
//
//}