You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
584 B
Go
37 lines
584 B
Go
package interfaces
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/fx"
|
|
)
|
|
|
|
type HandleFunc func(c *gin.Context) error
|
|
|
|
type Handler interface {
|
|
RegisterRouters(app gin.IRouter)
|
|
}
|
|
|
|
func AsHandler(f any) any {
|
|
return fx.Annotate(
|
|
f,
|
|
fx.As(new(Handler)),
|
|
fx.ResultTags(`group:"handlers"`),
|
|
)
|
|
}
|
|
|
|
type Params struct {
|
|
fx.In
|
|
Gin *gin.Engine
|
|
Handlers []Handler `group:"handlers"`
|
|
}
|
|
|
|
func RegisterHandlers(params Params) {
|
|
fmt.Println("注册路由")
|
|
api := params.Gin.Group("/api")
|
|
|
|
for _, handler := range params.Handlers {
|
|
handler.RegisterRouters(api)
|
|
}
|
|
}
|