优化函数定义
This commit is contained in:
parent
0a4a8a3c67
commit
cbfe92597e
@ -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)
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user