api to rpc

This commit is contained in:
withchao
2023-03-03 18:42:33 +08:00
parent 5e845c8fb6
commit 4deedb6856
4 changed files with 26 additions and 52 deletions
+18
View File
@@ -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))
}
+2 -2
View File
@@ -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()}
}