This commit is contained in:
76
backend_v1/app/http/v1/demo.go
Normal file
76
backend_v1/app/http/v1/demo.go
Normal file
@@ -0,0 +1,76 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"mime/multipart"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/providers/jwt"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type demo struct{}
|
||||
|
||||
type FooUploadReq struct {
|
||||
Folder string `json:"folder" form:"folder"` // 上传到指定文件夹
|
||||
}
|
||||
|
||||
type FooQuery struct {
|
||||
Search string `query:"search"` // 搜索关键词
|
||||
}
|
||||
|
||||
type FooHeader struct {
|
||||
ContentType string `header:"Content-Type"` // 内容类型
|
||||
}
|
||||
type Filter struct {
|
||||
Name string `query:"name"` // 名称
|
||||
Age int `query:"age"` // 年龄
|
||||
}
|
||||
|
||||
type ResponseItem struct{}
|
||||
|
||||
// Foo
|
||||
//
|
||||
// @Summary Test
|
||||
// @Description Test
|
||||
// @Tags Test
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
//
|
||||
// @Param id path int true "ID"
|
||||
// @Param query query Filter true "Filter"
|
||||
// @Param pager query requests.Pagination true "Pager"
|
||||
// @Success 200 {object} requests.Pager{list=ResponseItem} "成功"
|
||||
//
|
||||
// @Router /v1/medias/:id [post]
|
||||
// @Bind query query
|
||||
// @Bind pager query
|
||||
// @Bind header header
|
||||
// @Bind id path
|
||||
// @Bind req body
|
||||
// @Bind file file
|
||||
// @Bind claim local
|
||||
func (d *demo) Foo(
|
||||
ctx fiber.Ctx,
|
||||
id int,
|
||||
pager *requests.Pagination,
|
||||
query *FooQuery,
|
||||
header *FooHeader,
|
||||
claim *jwt.Claims,
|
||||
file *multipart.FileHeader,
|
||||
req *FooUploadReq,
|
||||
) error {
|
||||
_, err := services.Test.Test(ctx)
|
||||
if err != nil {
|
||||
// 示例:在控制器层自定义错误消息/附加数据
|
||||
appErr := errorx.Wrap(err).
|
||||
WithMsg("获取测试失败").
|
||||
WithData(fiber.Map{"route": "/v1/test"}).
|
||||
WithParams("handler", "Test.Hello")
|
||||
return appErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
37
backend_v1/app/http/v1/provider.gen.go
Executable file
37
backend_v1/app/http/v1/provider.gen.go
Executable file
@@ -0,0 +1,37 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"quyun/v2/app/middlewares"
|
||||
|
||||
"go.ipao.vip/atom"
|
||||
"go.ipao.vip/atom/container"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.ipao.vip/atom/opt"
|
||||
)
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
if err := container.Container.Provide(func() (*demo, error) {
|
||||
obj := &demo{}
|
||||
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
demo *demo,
|
||||
middlewares *middlewares.Middlewares,
|
||||
) (contracts.HttpRoute, error) {
|
||||
obj := &Routes{
|
||||
demo: demo,
|
||||
middlewares: middlewares,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}, atom.GroupRoutes); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
60
backend_v1/app/http/v1/routes.gen.go
Normal file
60
backend_v1/app/http/v1/routes.gen.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// Code generated by atomctl. DO NOT EDIT.
|
||||
|
||||
// Package v1 provides HTTP route definitions and registration
|
||||
// for the quyun/v2 application.
|
||||
package v1
|
||||
|
||||
import (
|
||||
"mime/multipart"
|
||||
"quyun/v2/app/middlewares"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/providers/jwt"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
_ "go.ipao.vip/atom"
|
||||
_ "go.ipao.vip/atom/contracts"
|
||||
. "go.ipao.vip/atom/fen"
|
||||
)
|
||||
|
||||
// Routes implements the HttpRoute contract and provides route registration
|
||||
// for all controllers in the v1 module.
|
||||
//
|
||||
// @provider contracts.HttpRoute atom.GroupRoutes
|
||||
type Routes struct {
|
||||
log *log.Entry `inject:"false"`
|
||||
middlewares *middlewares.Middlewares
|
||||
// Controller instances
|
||||
demo *demo
|
||||
}
|
||||
|
||||
// Prepare initializes the routes provider with logging configuration.
|
||||
func (r *Routes) Prepare() error {
|
||||
r.log = log.WithField("module", "routes.v1")
|
||||
r.log.Info("Initializing routes module")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Name returns the unique identifier for this routes provider.
|
||||
func (r *Routes) Name() string {
|
||||
return "v1"
|
||||
}
|
||||
|
||||
// Register registers all HTTP routes with the provided fiber router.
|
||||
// Each route is registered with its corresponding controller action and parameter bindings.
|
||||
func (r *Routes) Register(router fiber.Router) {
|
||||
// Register routes for controller: demo
|
||||
r.log.Debugf("Registering route: Post /v1/medias/:id -> demo.Foo")
|
||||
router.Post("/v1/medias/:id"[len(r.Path()):], Func7(
|
||||
r.demo.Foo,
|
||||
PathParam[int]("id"),
|
||||
Query[requests.Pagination]("pager"),
|
||||
Query[FooQuery]("query"),
|
||||
Header[FooHeader]("header"),
|
||||
Local[*jwt.Claims]("claim"),
|
||||
File[multipart.FileHeader]("file"),
|
||||
Body[FooUploadReq]("req"),
|
||||
))
|
||||
|
||||
r.log.Info("Successfully registered all routes")
|
||||
}
|
||||
9
backend_v1/app/http/v1/routes.manual.go
Normal file
9
backend_v1/app/http/v1/routes.manual.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package v1
|
||||
|
||||
func (r *Routes) Path() string {
|
||||
return "/v1"
|
||||
}
|
||||
|
||||
func (r *Routes) Middlewares() []any {
|
||||
return []any{}
|
||||
}
|
||||
Reference in New Issue
Block a user