registry: adopt micro/micro 69b0ac2e9140fee1cde043f5ecdab438a41898ee

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-12-13 13:51:09 +03:00
parent 92aec349c3
commit 762f20d179
2 changed files with 34 additions and 17 deletions

View File

@ -4,6 +4,8 @@ import (
"fmt"
"reflect"
"strings"
"unicode"
"unicode/utf8"
"github.com/unistack-org/micro/v3/metadata"
)
@ -21,6 +23,18 @@ func ExtractValue(v reflect.Type, d int) *Value {
v = v.Elem()
}
if len(v.Name()) == 0 {
return nil
}
// get the rune character
a, _ := utf8.DecodeRuneInString(string(v.Name()[0]))
// crude check for is unexported field
if unicode.IsLower(a) {
return nil
}
arg := &Value{
Name: v.Name(),
Type: v.Name(),
@ -91,6 +105,9 @@ func ExtractEndpoint(method reflect.Method) *Endpoint {
request := ExtractValue(reqType, 0)
response := ExtractValue(rspType, 0)
if request == nil || response == nil {
return nil
}
ep := &Endpoint{
Name: method.Name,

View File

@ -6,18 +6,18 @@ import (
"testing"
)
type testHandler struct{}
type TestHandler struct{}
type testRequest struct{}
type TestRequest struct{}
type testResponse struct{}
type TestResponse struct{}
func (t *testHandler) Test(ctx context.Context, req *testRequest, rsp *testResponse) error {
func (t *TestHandler) Test(ctx context.Context, req *TestRequest, rsp *TestResponse) error {
return nil
}
func TestExtractEndpoint(t *testing.T) {
handler := &testHandler{}
handler := &TestHandler{}
typ := reflect.TypeOf(handler)
var endpoints []*Endpoint
@ -29,35 +29,35 @@ func TestExtractEndpoint(t *testing.T) {
}
if i := len(endpoints); i != 1 {
t.Errorf("Expected 1 endpoint, have %d", i)
t.Fatalf("Expected 1 endpoint, have %d", i)
}
if endpoints[0].Name != "Test" {
t.Errorf("Expected handler Test, got %s", endpoints[0].Name)
t.Fatalf("Expected handler Test, got %s", endpoints[0].Name)
}
if endpoints[0].Request == nil {
t.Error("Expected non nil request")
t.Fatal("Expected non nil Request")
}
if endpoints[0].Response == nil {
t.Error("Expected non nil request")
t.Fatal("Expected non nil Request")
}
if endpoints[0].Request.Name != "testRequest" {
t.Errorf("Expected testRequest got %s", endpoints[0].Request.Name)
if endpoints[0].Request.Name != "TestRequest" {
t.Fatalf("Expected TestRequest got %s", endpoints[0].Request.Name)
}
if endpoints[0].Response.Name != "testResponse" {
t.Errorf("Expected testResponse got %s", endpoints[0].Response.Name)
if endpoints[0].Response.Name != "TestResponse" {
t.Fatalf("Expected TestResponse got %s", endpoints[0].Response.Name)
}
if endpoints[0].Request.Type != "testRequest" {
t.Errorf("Expected testRequest type got %s", endpoints[0].Request.Type)
if endpoints[0].Request.Type != "TestRequest" {
t.Fatalf("Expected TestRequest type got %s", endpoints[0].Request.Type)
}
if endpoints[0].Response.Type != "testResponse" {
t.Errorf("Expected testResponse type got %s", endpoints[0].Response.Type)
if endpoints[0].Response.Type != "TestResponse" {
t.Fatalf("Expected TestResponse type got %s", endpoints[0].Response.Type)
}
}