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.
34 lines
547 B
Go
34 lines
547 B
Go
![]()
3 weeks ago
|
package interfaces
|
||
|
|
||
|
import (
|
||
|
"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) {
|
||
|
api := params.Gin.Group("/api")
|
||
|
for _, handler := range params.Handlers {
|
||
|
handler.RegisterRouters(api)
|
||
|
}
|
||
|
}
|