|
|
@ -6,7 +6,6 @@ package base
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/alimy/mir/v3"
|
|
|
|
"github.com/alimy/mir/v3"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
@ -26,7 +25,13 @@ type BaseRender struct {
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (BaseServant) userFrom(c *gin.Context) (*core.User, bool) {
|
|
|
|
type JsonResp struct {
|
|
|
|
|
|
|
|
Code int `json:"code"`
|
|
|
|
|
|
|
|
Msg string `json:"msg,omitempty"`
|
|
|
|
|
|
|
|
Data any `json:",omitempty"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (BaseServant) UserFrom(c *gin.Context) (*core.User, bool) {
|
|
|
|
if u, exists := c.Get("USER"); exists {
|
|
|
|
if u, exists := c.Get("USER"); exists {
|
|
|
|
user, ok := u.(*core.User)
|
|
|
|
user, ok := u.(*core.User)
|
|
|
|
return user, ok
|
|
|
|
return user, ok
|
|
|
@ -45,33 +50,15 @@ func BindAny(c *gin.Context, obj any) mir.Error {
|
|
|
|
|
|
|
|
|
|
|
|
func RenderAny(c *gin.Context, data any, err mir.Error) {
|
|
|
|
func RenderAny(c *gin.Context, data any, err mir.Error) {
|
|
|
|
if err == nil {
|
|
|
|
if err == nil {
|
|
|
|
hostname, _ := os.Hostname()
|
|
|
|
c.JSON(http.StatusOK, &JsonResp{
|
|
|
|
if data == nil {
|
|
|
|
Code: 0,
|
|
|
|
data = gin.H{
|
|
|
|
Msg: "success",
|
|
|
|
"code": 0,
|
|
|
|
Data: data,
|
|
|
|
"msg": "success",
|
|
|
|
})
|
|
|
|
"tracehost": hostname,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
data = gin.H{
|
|
|
|
|
|
|
|
"code": 0,
|
|
|
|
|
|
|
|
"msg": "success",
|
|
|
|
|
|
|
|
"data": data,
|
|
|
|
|
|
|
|
"tracehost": hostname,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, data)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// TODO: error process logic
|
|
|
|
c.JSON(http.StatusInternalServerError, &JsonResp{
|
|
|
|
resp := gin.H{"code": err.StatusCode(), "msg": err.Error()}
|
|
|
|
Code: err.StatusCode(),
|
|
|
|
// xerr := &xerror.Error{}
|
|
|
|
Msg: err.Error(),
|
|
|
|
// if errors.As(err, xerr) {
|
|
|
|
})
|
|
|
|
// resp["code"], resp["msg"] = xerr.Code(), xerr.Msg()
|
|
|
|
|
|
|
|
// details := xerr.Details()
|
|
|
|
|
|
|
|
// if len(details) > 0 {
|
|
|
|
|
|
|
|
// resp["details"] = details
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
c.JSON(http.StatusInternalServerError, resp)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|