move helper to proper place
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
4c12e38c01
commit
2682f15b8e
@ -1,14 +1,12 @@
|
|||||||
package server
|
package registry
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/registry"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func extractValue(v reflect.Type, d int) *registry.Value {
|
func ExtractValue(v reflect.Type, d int) *Value {
|
||||||
if d == 3 {
|
if d == 3 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -20,7 +18,7 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
|||||||
v = v.Elem()
|
v = v.Elem()
|
||||||
}
|
}
|
||||||
|
|
||||||
arg := ®istry.Value{
|
arg := &Value{
|
||||||
Name: v.Name(),
|
Name: v.Name(),
|
||||||
Type: v.Name(),
|
Type: v.Name(),
|
||||||
}
|
}
|
||||||
@ -29,7 +27,7 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
|||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
for i := 0; i < v.NumField(); i++ {
|
for i := 0; i < v.NumField(); i++ {
|
||||||
f := v.Field(i)
|
f := v.Field(i)
|
||||||
val := extractValue(f.Type, d+1)
|
val := ExtractValue(f.Type, d+1)
|
||||||
if val == nil {
|
if val == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -61,7 +59,7 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
|||||||
return arg
|
return arg
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractEndpoint(method reflect.Method) *registry.Endpoint {
|
func ExtractEndpoint(method reflect.Method) *Endpoint {
|
||||||
if method.PkgPath != "" {
|
if method.PkgPath != "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -87,10 +85,10 @@ func extractEndpoint(method reflect.Method) *registry.Endpoint {
|
|||||||
stream = true
|
stream = true
|
||||||
}
|
}
|
||||||
|
|
||||||
request := extractValue(reqType, 0)
|
request := ExtractValue(reqType, 0)
|
||||||
response := extractValue(rspType, 0)
|
response := ExtractValue(rspType, 0)
|
||||||
|
|
||||||
ep := ®istry.Endpoint{
|
ep := &Endpoint{
|
||||||
Name: method.Name,
|
Name: method.Name,
|
||||||
Request: request,
|
Request: request,
|
||||||
Response: response,
|
Response: response,
|
@ -1,11 +1,9 @@
|
|||||||
package server
|
package registry
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/registry"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type testHandler struct{}
|
type testHandler struct{}
|
||||||
@ -22,10 +20,10 @@ func TestExtractEndpoint(t *testing.T) {
|
|||||||
handler := &testHandler{}
|
handler := &testHandler{}
|
||||||
typ := reflect.TypeOf(handler)
|
typ := reflect.TypeOf(handler)
|
||||||
|
|
||||||
var endpoints []*registry.Endpoint
|
var endpoints []*Endpoint
|
||||||
|
|
||||||
for m := 0; m < typ.NumMethod(); m++ {
|
for m := 0; m < typ.NumMethod(); m++ {
|
||||||
if e := extractEndpoint(typ.Method(m)); e != nil {
|
if e := ExtractEndpoint(typ.Method(m)); e != nil {
|
||||||
endpoints = append(endpoints, e)
|
endpoints = append(endpoints, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user