优化函数定义

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