diff --git a/api/hero/v1/hero.go b/api/hero/v1/hero.go index bcffb94..b504fb4 100644 --- a/api/hero/v1/hero.go +++ b/api/hero/v1/hero.go @@ -15,14 +15,12 @@ type GetOneRes struct { // GetListReq GetListRes 列表返回所有角色 type GetListReq struct { - g.Meta `path:"/getList" method:"get" tags:"Hero" summary:"Get all hero"` -} -type GetListRes struct { - Records []*EpicHeroVO `json:"list"` // ✅ 返回一个数组 + g.Meta `path:"/app-api/epic/hero/list-all" method:"get" tags:"Hero" summary:"Get all hero"` } +type GetListRes []*EpicHeroVO type GetDetailReq struct { - g.Meta `path:"/getDetail" method:"get" tags:"Hero" summary:"Get hero detail by code"` + g.Meta `path:"/app-api/epic/hero/hero-detail" method:"get" tags:"Hero" summary:"Get hero detail by code"` Code string `v:"required" dc:"角色code"` } type GetDetailRes struct { diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index e861223..ca571e8 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -8,6 +8,11 @@ import ( "github.com/gogf/gf/v2/os/gcmd" ) +func CORS(r *ghttp.Request) { + r.Response.CORSDefault() + r.Middleware.Next() +} + var ( Main = gcmd.Command{ Name: "main", @@ -15,6 +20,7 @@ var ( Brief: "start http server", Func: func(ctx context.Context, parser *gcmd.Parser) (err error) { s := g.Server() + s.Use(CORS) s.Group("/", func(group *ghttp.RouterGroup) { group.Middleware(ghttp.MiddlewareHandlerResponse) group.Bind( diff --git a/internal/controller/hero/hero_v1.go b/internal/controller/hero/hero_v1.go index 2a4d7cc..cd62bd0 100644 --- a/internal/controller/hero/hero_v1.go +++ b/internal/controller/hero/hero_v1.go @@ -26,9 +26,7 @@ func (c *ControllerV1) GetList(ctx context.Context, req *v1.GetListReq) (res *v1 } // 构造响应 - res = &v1.GetListRes{ - Records: list, // ✅ 正确赋值字段 - } + res = (*v1.GetListRes)(&list) return res, nil }