mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-05 16:06:51 +08:00
初次提交
This commit is contained in:
33
api/api.go
Normal file
33
api/api.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"msm/consts/ctxflag"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func rOk(ctx *gin.Context, message string, data any) {
|
||||
jsonData := map[string]any{
|
||||
"code": 0,
|
||||
"msg": message,
|
||||
}
|
||||
if data != nil {
|
||||
jsonData["data"] = data
|
||||
}
|
||||
ctx.JSON(http.StatusOK, jsonData)
|
||||
}
|
||||
|
||||
func errCheck(ctx *gin.Context, isErr bool, errData any) {
|
||||
if !isErr {
|
||||
return
|
||||
}
|
||||
if err, ok := errData.(error); ok {
|
||||
ctx.Set(ctxflag.ERR, err)
|
||||
}
|
||||
if err, ok := errData.(string); ok {
|
||||
ctx.Set(ctxflag.ERR, errors.New(err))
|
||||
}
|
||||
panic(0)
|
||||
}
|
Reference in New Issue
Block a user