mirror of
https://gitee.com/shikong-sk/gofiber-study
synced 2025-02-23 23:32:15 +08:00
注册优化
This commit is contained in:
parent
4102109984
commit
b06fedf311
@ -1 +1,20 @@
|
|||||||
package auth
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"gofiber.study.skcks.cn/controller/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Controller struct {
|
||||||
|
*types.Controller
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Controller) GetRouter() fiber.Router {
|
||||||
|
return c.Router
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewController(app *fiber.App) *Controller {
|
||||||
|
return &Controller{
|
||||||
|
Controller: types.NewController(app, "/auth"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/gofiber/swagger"
|
"github.com/gofiber/swagger"
|
||||||
"gofiber.study.skcks.cn/common/errorx"
|
"gofiber.study.skcks.cn/common/errorx"
|
||||||
|
"gofiber.study.skcks.cn/controller/auth"
|
||||||
"gofiber.study.skcks.cn/controller/casbin"
|
"gofiber.study.skcks.cn/controller/casbin"
|
||||||
"gofiber.study.skcks.cn/controller/test"
|
"gofiber.study.skcks.cn/controller/test"
|
||||||
"gofiber.study.skcks.cn/controller/types"
|
"gofiber.study.skcks.cn/controller/types"
|
||||||
@ -12,21 +13,23 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func RegisterController(app *fiber.App) {
|
func RegisterController(app *fiber.App) {
|
||||||
controllers := make([]types.ControllerInterface, 0)
|
controllers := []types.ControllerInterface{
|
||||||
controllers = append(controllers, user.NewController(app))
|
auth.NewController(app),
|
||||||
controllers = append(controllers, casbin.NewController(app))
|
user.NewController(app),
|
||||||
controllers = append(controllers, test.NewController(app))
|
casbin.NewController(app),
|
||||||
|
test.NewController(app),
|
||||||
|
}
|
||||||
|
|
||||||
|
args := make([]reflect.Value, 0)
|
||||||
for _, controller := range controllers {
|
for _, controller := range controllers {
|
||||||
reflectRegisterRoute(controller)
|
reflectRegisterRoute(controller, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func reflectRegisterRoute(controller interface{}) {
|
func reflectRegisterRoute(controller interface{}, args []reflect.Value) {
|
||||||
t := reflect.ValueOf(controller)
|
t := reflect.ValueOf(controller)
|
||||||
for i := 0; i < t.NumMethod(); i++ {
|
for i := 0; i < t.NumMethod(); i++ {
|
||||||
method := t.Method(i)
|
method := t.Method(i)
|
||||||
args := make([]reflect.Value, 0)
|
|
||||||
method.Call(args)
|
method.Call(args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user