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 (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"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 {
|
||||
return nil
|
||||
}
|
||||
@ -20,7 +18,7 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
||||
v = v.Elem()
|
||||
}
|
||||
|
||||
arg := ®istry.Value{
|
||||
arg := &Value{
|
||||
Name: v.Name(),
|
||||
Type: v.Name(),
|
||||
}
|
||||
@ -29,7 +27,7 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
||||
case reflect.Struct:
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
f := v.Field(i)
|
||||
val := extractValue(f.Type, d+1)
|
||||
val := ExtractValue(f.Type, d+1)
|
||||
if val == nil {
|
||||
continue
|
||||
}
|
||||
@ -61,7 +59,7 @@ func extractValue(v reflect.Type, d int) *registry.Value {
|
||||
return arg
|
||||
}
|
||||
|
||||
func extractEndpoint(method reflect.Method) *registry.Endpoint {
|
||||
func ExtractEndpoint(method reflect.Method) *Endpoint {
|
||||
if method.PkgPath != "" {
|
||||
return nil
|
||||
}
|
||||
@ -87,10 +85,10 @@ func extractEndpoint(method reflect.Method) *registry.Endpoint {
|
||||
stream = true
|
||||
}
|
||||
|
||||
request := extractValue(reqType, 0)
|
||||
response := extractValue(rspType, 0)
|
||||
request := ExtractValue(reqType, 0)
|
||||
response := ExtractValue(rspType, 0)
|
||||
|
||||
ep := ®istry.Endpoint{
|
||||
ep := &Endpoint{
|
||||
Name: method.Name,
|
||||
Request: request,
|
||||
Response: response,
|
@ -1,11 +1,9 @@
|
||||
package server
|
||||
package registry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/unistack-org/micro/v3/registry"
|
||||
)
|
||||
|
||||
type testHandler struct{}
|
||||
@ -22,10 +20,10 @@ func TestExtractEndpoint(t *testing.T) {
|
||||
handler := &testHandler{}
|
||||
typ := reflect.TypeOf(handler)
|
||||
|
||||
var endpoints []*registry.Endpoint
|
||||
var endpoints []*Endpoint
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user