优化函数定义

This commit is contained in:
白茶清欢 2024-07-19 22:31:18 +08:00
parent 0a4a8a3c67
commit cbfe92597e
2 changed files with 5 additions and 5 deletions

View File

@ -27,9 +27,9 @@ type IApi interface {
GetHandler() gin.HandlerFunc
}
// RouterFunc 注册路由的函数
// RegisterFunc 注册路由的函数
//
// Author : go_developer@163.com<白茶清欢>
//
// Date : 3:09 下午 2021/3/26
type RouterFunc func() (method string, uri string, handlerFunc gin.HandlerFunc, middlewareList []gin.HandlerFunc)
type RegisterFunc func() (method string, uri string, handlerFunc gin.HandlerFunc, middlewareList []gin.HandlerFunc)

View File

@ -35,7 +35,7 @@ func DisableDebugLog() {
// Author : go_developer@163.com<白茶清欢>
//
// Date : 2:14 下午 2021/3/26
func RegisterRouter(router *gin.Engine, apiInstanceList ...interface{}) error {
func RegisterRouter(router *gin.Engine, apiInstanceList ...any) error {
for _, apiInstance := range apiInstanceList {
if nil == apiInstance {
continue
@ -69,7 +69,7 @@ func RegisterRouter(router *gin.Engine, apiInstanceList ...interface{}) error {
}
apiFuncList := val.Method(i).Call(nil)
for _, apiFuncVal := range apiFuncList {
apiFunc, ok := apiFuncVal.Interface().(RouterFunc)
apiFunc, ok := apiFuncVal.Interface().(RegisterFunc)
if !ok {
continue
}
@ -82,7 +82,7 @@ func RegisterRouter(router *gin.Engine, apiInstanceList ...interface{}) error {
}
case reflect.Func:
api, ok := apiInstance.(RouterFunc)
api, ok := apiInstance.(RegisterFunc)
if !ok {
err := errors.New("函数方式注册路由必须是 RouterFunc")
routerLog(err.Error())