注册优化

This commit is contained in:
Shikong 2022-10-06 17:05:15 +08:00
parent 4102109984
commit b06fedf311
2 changed files with 29 additions and 7 deletions

View File

@ -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"),
}
}

View File

@ -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)
} }
} }