mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-20 08:49:01 +08:00
api to rpc
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package apiresp
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GinError(c *gin.Context, err error) {
|
||||
if err == nil {
|
||||
GinSuccess(c, nil)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, apiError(err))
|
||||
}
|
||||
|
||||
func GinSuccess(c *gin.Context, data any) {
|
||||
c.JSON(http.StatusOK, apiSuccess(data))
|
||||
}
|
||||
@@ -7,12 +7,12 @@ type ApiResponse struct {
|
||||
Data any `json:"data"`
|
||||
}
|
||||
|
||||
func Success(data any) *ApiResponse {
|
||||
func apiSuccess(data any) *ApiResponse {
|
||||
return &ApiResponse{
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
func Error(err error) *ApiResponse {
|
||||
func apiError(err error) *ApiResponse {
|
||||
return &ApiResponse{ErrCode: 10000, ErrMsg: err.Error()}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user