From cdfeaa7e208c72374d63a911176b6a641ba2397d Mon Sep 17 00:00:00 2001 From: Gorbunov Kirill Andreevich Date: Tue, 27 Feb 2024 22:36:18 +0300 Subject: [PATCH] #97 add As for all interface. --- micro.go | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/micro.go b/micro.go index c167e1b4..c86955c8 100644 --- a/micro.go +++ b/micro.go @@ -33,24 +33,41 @@ func As(b any, target any) bool { return false } targetType := typ.Elem() - if targetType.Kind() != reflect.Interface && - !(targetType.Implements(brokerType) || - targetType.Implements(loggerType) || - targetType.Implements(clientType) || - targetType.Implements(serverType) || - targetType.Implements(codecType) || - targetType.Implements(flowType) || - targetType.Implements(fsmType) || - targetType.Implements(meterType) || - targetType.Implements(registerType) || - targetType.Implements(resolverType) || - targetType.Implements(selectorType) || - targetType.Implements(storeType) || - targetType.Implements(syncType) || - targetType.Implements(tracerType) || - targetType.Implements(serviceType) || - targetType.Implements(routerType)) { - return false + if targetType.Kind() != reflect.Interface { + switch { + case targetType.Implements(brokerType): + break + case targetType.Implements(loggerType): + break + case targetType.Implements(clientType): + break + case targetType.Implements(serverType): + break + case targetType.Implements(codecType): + break + case targetType.Implements(flowType): + break + case targetType.Implements(fsmType): + break + 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 + } } if reflect.TypeOf(b).AssignableTo(targetType) { val.Elem().Set(reflect.ValueOf(b))