package router import ( "errors" "net/http" "github.com/gin-gonic/gin" "github.com/go-admin-team/go-admin-core/sdk/api" jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth" "go-admin/app/bell/event" ) type eventHandler struct{ api.Api } func registerEventRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { handler := eventHandler{} v1.GET("/events/:id", authMiddleware.MiddlewareFunc(), handler.Get) } func (h eventHandler) Get(c *gin.Context) { h.MakeContext(c).MakeOrm() if h.Errors != nil { h.Error(http.StatusInternalServerError, errors.New("数据库连接获取失败"), "数据库连接获取失败") return } item, err := event.NewService(h.Orm).Get(c.Request.Context(), c.Param("id")) if err != nil { if errors.Is(err, event.ErrNotFound) { h.Error(http.StatusNotFound, event.ErrNotFound, event.ErrNotFound.Error()) return } h.Logger.Errorf("load Bell event failed: %v", err) h.Error(http.StatusInternalServerError, errors.New("读取事件失败"), "读取事件失败") return } h.OK(item, "查询成功") }