2024-07-23 10:23:43 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2024-07-31 16:49:14 +08:00
|
|
|
"gitea.bvbej.com/bvbej/base-golang/pkg/websocket/peer"
|
2024-07-23 10:23:43 +08:00
|
|
|
"reflect"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
typeOfError = reflect.TypeOf((*error)(nil)).Elem()
|
|
|
|
typeOfBytes = reflect.TypeOf(([]byte)(nil))
|
|
|
|
typeOfSession = reflect.TypeOf(peer.NewSession(nil))
|
|
|
|
)
|
|
|
|
|
|
|
|
// 方法检测
|
|
|
|
func isHandlerMethod(method reflect.Method) bool {
|
|
|
|
mt := method.Type
|
|
|
|
if method.PkgPath != "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if mt.NumIn() != 3 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if mt.NumOut() != 2 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if t1 := mt.In(1); t1.Kind() != reflect.Ptr || t1 != typeOfSession {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (mt.In(2).Kind() != reflect.Ptr && mt.In(2) != typeOfBytes) || mt.Out(1) != typeOfError || mt.Out(0).Kind() != reflect.Ptr {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|