#97 add As for all interface.
Some checks failed
lint / lint (pull_request) Has been cancelled
pr / test (pull_request) Has been cancelled

This commit is contained in:
Gorbunov Kirill Andreevich 2024-02-27 22:36:18 +03:00
parent c09674ae92
commit cdfeaa7e20

View File

@ -33,25 +33,42 @@ func As(b any, target any) bool {
return false return false
} }
targetType := typ.Elem() targetType := typ.Elem()
if targetType.Kind() != reflect.Interface && if targetType.Kind() != reflect.Interface {
!(targetType.Implements(brokerType) || switch {
targetType.Implements(loggerType) || case targetType.Implements(brokerType):
targetType.Implements(clientType) || break
targetType.Implements(serverType) || case targetType.Implements(loggerType):
targetType.Implements(codecType) || break
targetType.Implements(flowType) || case targetType.Implements(clientType):
targetType.Implements(fsmType) || break
targetType.Implements(meterType) || case targetType.Implements(serverType):
targetType.Implements(registerType) || break
targetType.Implements(resolverType) || case targetType.Implements(codecType):
targetType.Implements(selectorType) || break
targetType.Implements(storeType) || case targetType.Implements(flowType):
targetType.Implements(syncType) || break
targetType.Implements(tracerType) || case targetType.Implements(fsmType):
targetType.Implements(serviceType) || break
targetType.Implements(routerType)) { case targetType.Implements(meterType):
break
case targetType.Implements(registerType):
break
case targetType.Implements(resolverType):
break
case targetType.Implements(selectorType):
break
case targetType.Implements(storeType):
break
case targetType.Implements(syncType):
break
case targetType.Implements(serviceType):
break
case targetType.Implements(routerType):
break
default:
return false return false
} }
}
if reflect.TypeOf(b).AssignableTo(targetType) { if reflect.TypeOf(b).AssignableTo(targetType) {
val.Elem().Set(reflect.ValueOf(b)) val.Elem().Set(reflect.ValueOf(b))
return true return true