From 3dd911fb3317f7f5dfc9638182415a83bdd05a85 Mon Sep 17 00:00:00 2001 From: Asim Date: Fri, 25 Dec 2015 01:06:51 +0000 Subject: [PATCH] Stop recursive loop where its a recursive type --- server/extractor.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/server/extractor.go b/server/extractor.go index 5b8f1223..9833ca58 100644 --- a/server/extractor.go +++ b/server/extractor.go @@ -20,7 +20,10 @@ func init() { } } -func extractValue(v reflect.Type) *registry.Value { +func extractValue(v reflect.Type, d int) *registry.Value { + if d == 3 { + return nil + } if v == nil { return nil } @@ -37,7 +40,10 @@ func extractValue(v reflect.Type) *registry.Value { switch v.Kind() { case reflect.Struct: for i := 0; i < v.NumField(); i++ { - val := extractValue(v.Field(i).Type) + val := extractValue(v.Field(i).Type, d+1) + if val == nil { + continue + } val.Name = v.Field(i).Name arg.Values = append(arg.Values, val) } @@ -47,7 +53,10 @@ func extractValue(v reflect.Type) *registry.Value { p = p.Elem() } arg.Type = "[]" + p.Name() - arg.Values = append(arg.Values, extractValue(v.Elem())) + val := extractValue(v.Elem(), d+1) + if val != nil { + arg.Values = append(arg.Values, val) + } } return arg @@ -77,8 +86,8 @@ func extractEndpoint(method reflect.Method) *registry.Endpoint { stream = true } - request := extractValue(reqType) - response := extractValue(rspType) + request := extractValue(reqType, 0) + response := extractValue(rspType, 0) return ®istry.Endpoint{ Name: method.Name, @@ -102,7 +111,7 @@ func extractSubValue(typ reflect.Type) *registry.Value { default: return nil } - return extractValue(reqType) + return extractValue(reqType, 0) } func extractAddress(addr string) (string, error) {