Skip to content
Snippets Groups Projects
Commit 2dd44a2d authored by AlexStocks's avatar AlexStocks
Browse files

Fix: Id -> ID

parent 6b12856c
No related branches found
No related tags found
No related merge requests found
Showing
with 91 additions and 91 deletions
......@@ -340,7 +340,7 @@ func createInstance(url *common.URL) (registry.ServiceInstance, error) {
ServiceName: appConfig.Name,
Host: host,
Port: int(port),
Id: host + constant.KEY_SEPARATOR + url.Port,
ID: host + constant.KEY_SEPARATOR + url.Port,
Enable: true,
Healthy: true,
Metadata: metadata,
......
......@@ -46,7 +46,7 @@ type ReferenceConfig struct {
id string
InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty" property:"interface"`
Check *bool `yaml:"check" json:"check,omitempty" property:"check"`
Url string `yaml:"url" json:"url,omitempty" property:"url"`
URL string `yaml:"url" json:"url,omitempty" property:"url"`
Filter string `yaml:"filter" json:"filter,omitempty" property:"filter"`
Protocol string `default:"dubbo" yaml:"protocol" json:"protocol,omitempty" property:"protocol"`
Registry string `yaml:"registry" json:"registry,omitempty" property:"registry"`
......@@ -94,40 +94,40 @@ func (c *ReferenceConfig) Refer(_ interface{}) {
cfgURL := common.NewURLWithOptions(
common.WithPath(c.InterfaceName),
common.WithProtocol(c.Protocol),
common.WithParams(c.getUrlMap()),
common.WithParams(c.getURLMap()),
common.WithParamsValue(constant.BEAN_NAME_KEY, c.id),
)
if c.ForceTag {
cfgURL.AddParam(constant.ForceUseTag, "true")
}
c.postProcessConfig(cfgURL)
if c.Url != "" {
if c.URL != "" {
// 1. user specified URL, could be peer-to-peer address, or register center's address.
urlStrings := gxstrings.RegSplit(c.Url, "\\s*[;]+\\s*")
urlStrings := gxstrings.RegSplit(c.URL, "\\s*[;]+\\s*")
for _, urlStr := range urlStrings {
serviceUrl, err := common.NewURL(urlStr)
serviceURL, err := common.NewURL(urlStr)
if err != nil {
panic(fmt.Sprintf("user specified URL %v refer error, error message is %v ", urlStr, err.Error()))
}
if serviceUrl.Protocol == constant.REGISTRY_PROTOCOL {
serviceUrl.SubURL = cfgURL
c.urls = append(c.urls, serviceUrl)
if serviceURL.Protocol == constant.REGISTRY_PROTOCOL {
serviceURL.SubURL = cfgURL
c.urls = append(c.urls, serviceURL)
} else {
if serviceUrl.Path == "" {
serviceUrl.Path = "/" + c.InterfaceName
if serviceURL.Path == "" {
serviceURL.Path = "/" + c.InterfaceName
}
// merge url need to do
newUrl := common.MergeUrl(serviceUrl, cfgURL)
c.urls = append(c.urls, newUrl)
newURL := common.MergeURL(serviceURL, cfgURL)
c.urls = append(c.urls, newURL)
}
}
} else {
// 2. assemble SubURL from register center's configuration mode
c.urls = loadRegistries(c.Registry, consumerConfig.Registries, common.CONSUMER)
// set url to regUrls
for _, regUrl := range c.urls {
regUrl.SubURL = cfgURL
// set url to regURLs
for _, regURL := range c.urls {
regURL.SubURL = cfgURL
}
}
......@@ -135,24 +135,24 @@ func (c *ReferenceConfig) Refer(_ interface{}) {
c.invoker = extension.GetProtocol(c.urls[0].Protocol).Refer(c.urls[0])
} else {
invokers := make([]protocol.Invoker, 0, len(c.urls))
var regUrl *common.URL
var regURL *common.URL
for _, u := range c.urls {
invokers = append(invokers, extension.GetProtocol(u.Protocol).Refer(u))
if u.Protocol == constant.REGISTRY_PROTOCOL {
regUrl = u
regURL = u
}
}
// TODO(decouple from directory, config should not depend on directory module)
var hitClu string
if regUrl != nil {
if regURL != nil {
// for multi-subscription scenario, use 'zone-aware' policy by default
hitClu = constant.ZONEAWARE_CLUSTER_NAME
} else {
// not a registry url, must be direct invoke.
hitClu = constant.FAILOVER_CLUSTER_NAME
if len(invokers) > 0 {
u := invokers[0].GetUrl()
u := invokers[0].GetURL()
if nil != &u {
hitClu = u.GetParam(constant.CLUSTER_KEY, constant.ZONEAWARE_CLUSTER_NAME)
}
......@@ -192,7 +192,7 @@ func (c *ReferenceConfig) GetProxy() *proxy.Proxy {
return c.pxy
}
func (c *ReferenceConfig) getUrlMap() url.Values {
func (c *ReferenceConfig) getURLMap() url.Values {
urlMap := url.Values{}
// first set user params
for k, v := range c.Params {
......
......@@ -235,7 +235,7 @@ func TestReferP2P(t *testing.T) {
doInitConsumer()
extension.SetProtocol("dubbo", GetProtocol)
m := consumerConfig.References["MockService"]
m.Url = "dubbo://127.0.0.1:20000"
m.URL = "dubbo://127.0.0.1:20000"
for _, reference := range consumerConfig.References {
reference.Refer(nil)
......@@ -249,7 +249,7 @@ func TestReferMultiP2P(t *testing.T) {
doInitConsumer()
extension.SetProtocol("dubbo", GetProtocol)
m := consumerConfig.References["MockService"]
m.Url = "dubbo://127.0.0.1:20000;dubbo://127.0.0.2:20000"
m.URL = "dubbo://127.0.0.1:20000;dubbo://127.0.0.2:20000"
for _, reference := range consumerConfig.References {
reference.Refer(nil)
......@@ -264,7 +264,7 @@ func TestReferMultiP2PWithReg(t *testing.T) {
extension.SetProtocol("dubbo", GetProtocol)
extension.SetProtocol("registry", GetProtocol)
m := consumerConfig.References["MockService"]
m.Url = "dubbo://127.0.0.1:20000;registry://127.0.0.2:20000"
m.URL = "dubbo://127.0.0.1:20000;registry://127.0.0.2:20000"
for _, reference := range consumerConfig.References {
reference.Refer(nil)
......@@ -292,11 +292,11 @@ func TestForking(t *testing.T) {
extension.SetProtocol("dubbo", GetProtocol)
extension.SetProtocol("registry", GetProtocol)
m := consumerConfig.References["MockService"]
m.Url = "dubbo://127.0.0.1:20000;registry://127.0.0.2:20000"
m.URL = "dubbo://127.0.0.1:20000;registry://127.0.0.2:20000"
for _, reference := range consumerConfig.References {
reference.Refer(nil)
forks := int(reference.invoker.GetUrl().GetParamInt(constant.FORKS_KEY, constant.DEFAULT_FORKS))
forks := int(reference.invoker.GetURL().GetParamInt(constant.FORKS_KEY, constant.DEFAULT_FORKS))
assert.Equal(t, 5, forks)
assert.NotNil(t, reference.pxy)
assert.NotNil(t, reference.Cluster)
......@@ -309,16 +309,16 @@ func TestSticky(t *testing.T) {
extension.SetProtocol("dubbo", GetProtocol)
extension.SetProtocol("registry", GetProtocol)
m := consumerConfig.References["MockService"]
m.Url = "dubbo://127.0.0.1:20000;registry://127.0.0.2:20000"
m.URL = "dubbo://127.0.0.1:20000;registry://127.0.0.2:20000"
reference := consumerConfig.References["MockService"]
reference.Refer(nil)
referenceSticky := reference.invoker.GetUrl().GetParam(constant.STICKY_KEY, "false")
referenceSticky := reference.invoker.GetURL().GetParam(constant.STICKY_KEY, "false")
assert.Equal(t, "false", referenceSticky)
method0StickKey := reference.invoker.GetUrl().GetMethodParam(reference.Methods[0].Name, constant.STICKY_KEY, "false")
method0StickKey := reference.invoker.GetURL().GetMethodParam(reference.Methods[0].Name, constant.STICKY_KEY, "false")
assert.Equal(t, "false", method0StickKey)
method1StickKey := reference.invoker.GetUrl().GetMethodParam(reference.Methods[1].Name, constant.STICKY_KEY, "false")
method1StickKey := reference.invoker.GetURL().GetMethodParam(reference.Methods[1].Name, constant.STICKY_KEY, "false")
assert.Equal(t, "true", method1StickKey)
}
......@@ -340,13 +340,13 @@ func (*mockRegistryProtocol) Refer(url *common.URL) protocol.Invoker {
}
func (*mockRegistryProtocol) Export(invoker protocol.Invoker) protocol.Exporter {
registryUrl := getRegistryUrl(invoker)
if registryUrl.Protocol == "service-discovery" {
registryURL := getRegistryURL(invoker)
if registryURL.Protocol == "service-discovery" {
metaDataService, err := extension.GetMetadataService(GetApplicationConfig().MetadataType)
if err != nil {
panic(err)
}
ok, err := metaDataService.ExportURL(invoker.GetUrl().SubURL.Clone())
ok, err := metaDataService.ExportURL(invoker.GetURL().SubURL.Clone())
if err != nil {
panic(err)
}
......@@ -361,9 +361,9 @@ func (*mockRegistryProtocol) Destroy() {
// Destroy is a mock function
}
func getRegistryUrl(invoker protocol.Invoker) *common.URL {
func getRegistryURL(invoker protocol.Invoker) *common.URL {
// here add * for return a new url
url := invoker.GetUrl()
url := invoker.GetURL()
// if the protocol == registry ,set protocol the registry value in url.params
if url.Protocol == constant.REGISTRY_PROTOCOL {
protocol := url.GetParam(constant.REGISTRY_KEY, "")
......
......@@ -182,8 +182,8 @@ func (n *nacosDynamicConfiguration) GetDone() chan struct{} {
return n.done
}
// GetUrl Get Url
func (n *nacosDynamicConfiguration) GetUrl() *common.URL {
// GetURL Get URL
func (n *nacosDynamicConfiguration) GetURL() *common.URL {
return n.url
}
......
......@@ -44,7 +44,7 @@ func TestDefaultAuthenticator_Authenticate(t *testing.T) {
testurl.SetParam(constant.SECRET_ACCESS_KEY_KEY, secret)
parmas := []interface{}{"OK", struct {
Name string
Id int64
ID int64
}{"YUYU", 1}}
inv := invocation.NewRPCInvocation("test", parmas, nil)
requestTime := strconv.Itoa(int(time.Now().Unix() * 1000))
......
......@@ -47,7 +47,7 @@ func TestProviderAuthFilter_Invoke(t *testing.T) {
"OK",
struct {
Name string
Id int64
ID int64
}{"YUYU", 1},
}
inv := invocation.NewRPCInvocation("test", parmas, nil)
......
......@@ -64,7 +64,7 @@ func TestSignWithParams(t *testing.T) {
params := []interface{}{
"a", 1, struct {
Name string
Id int64
ID int64
}{"YuYu", 1},
}
signature, _ := SignWithParams(params, metadata, key)
......@@ -84,13 +84,13 @@ func Test_toBytes(t *testing.T) {
params := []interface{}{
"a", 1, struct {
Name string
Id int64
ID int64
}{"YuYu", 1},
}
params2 := []interface{}{
"a", 1, struct {
Name string
Id int64
ID int64
}{"YuYu", 1},
}
jsonBytes, _ := toBytes(params)
......
......@@ -57,13 +57,13 @@ func (def *ServiceDefinition) String() string {
}
var param strings.Builder
for _, d := range m.Parameters {
param.WriteString(fmt.Sprintf("{id:%v,type:%v,builderName:%v}", d.Id, d.Type, d.TypeBuilderName))
param.WriteString(fmt.Sprintf("{id:%v,type:%v,builderName:%v}", d.ID, d.Type, d.TypeBuilderName))
}
methodStr.WriteString(fmt.Sprintf("{name:%v,parameterTypes:[%v],returnType:%v,params:[%v] }", m.Name, paramType.String(), m.ReturnType, param.String()))
}
var types strings.Builder
for _, d := range def.Types {
types.WriteString(fmt.Sprintf("{id:%v,type:%v,builderName:%v}", d.Id, d.Type, d.TypeBuilderName))
types.WriteString(fmt.Sprintf("{id:%v,type:%v,builderName:%v}", d.ID, d.Type, d.TypeBuilderName))
}
return fmt.Sprintf("{canonicalName:%v, codeSource:%v, methods:[%v], types:[%v]}", def.CanonicalName, def.CodeSource, methodStr.String(), types.String())
}
......@@ -84,7 +84,7 @@ type MethodDefinition struct {
// TypeDefinition is the describer of type definition
type TypeDefinition struct {
Id string
ID string
Type string
Items []TypeDefinition
Enums []string
......
......@@ -23,7 +23,7 @@ import (
)
type User struct {
Id string
ID string
Name string
Age int32
Time time.Time
......
......@@ -47,7 +47,7 @@ func TestCreateProxy(t *testing.T) {
return &mockProtocol{}
})
ins := &registry.DefaultServiceInstance{
Id: "test-id",
ID: "test-id",
ServiceName: "com.dubbo",
Host: "localhost",
Port: 8080,
......
......@@ -81,7 +81,7 @@ func createPxy() service.MetadataService {
})
ins := &registry.DefaultServiceInstance{
Id: "test-id",
ID: "test-id",
ServiceName: "com.dubbo",
Host: "localhost",
Port: 8080,
......
......@@ -83,7 +83,7 @@ func createProxy() service.MetadataService {
prepareTest()
ins := &registry.DefaultServiceInstance{
Id: "test-id",
ID: "test-id",
ServiceName: "com.dubbo",
Host: "localhost",
Port: 8080,
......@@ -110,34 +110,34 @@ func (m *mockMetadataReportFactory) CreateMetadataReport(*common.URL) report.Met
type mockMetadataReport struct{}
func (m mockMetadataReport) StoreProviderMetadata(*identifier.MetadataIdentifier, string) error {
func (m mockMetadataReport) StoreProviderMetadata(*identifier.MetadataIDentifier, string) error {
panic("implement me")
}
func (m mockMetadataReport) StoreConsumerMetadata(*identifier.MetadataIdentifier, string) error {
func (m mockMetadataReport) StoreConsumerMetadata(*identifier.MetadataIDentifier, string) error {
panic("implement me")
}
func (m mockMetadataReport) SaveServiceMetadata(*identifier.ServiceMetadataIdentifier, *common.URL) error {
func (m mockMetadataReport) SaveServiceMetadata(*identifier.ServiceMetadataIDentifier, *common.URL) error {
return nil
}
func (m mockMetadataReport) RemoveServiceMetadata(*identifier.ServiceMetadataIdentifier) error {
func (m mockMetadataReport) RemoveServiceMetadata(*identifier.ServiceMetadataIDentifier) error {
panic("implement me")
}
func (m mockMetadataReport) GetExportedURLs(*identifier.ServiceMetadataIdentifier) ([]string, error) {
func (m mockMetadataReport) GetExportedURLs(*identifier.ServiceMetadataIDentifier) ([]string, error) {
return []string{"mock://localhost1", "mock://localhost2"}, nil
}
func (m mockMetadataReport) SaveSubscribedData(*identifier.SubscriberMetadataIdentifier, string) error {
func (m mockMetadataReport) SaveSubscribedData(*identifier.SubscriberMetadataIDentifier, string) error {
return nil
}
func (m mockMetadataReport) GetSubscribedURLs(*identifier.SubscriberMetadataIdentifier) ([]string, error) {
func (m mockMetadataReport) GetSubscribedURLs(*identifier.SubscriberMetadataIDentifier) ([]string, error) {
panic("implement me")
}
func (m mockMetadataReport) GetServiceDefinition(*identifier.MetadataIdentifier) (string, error) {
func (m mockMetadataReport) GetServiceDefinition(*identifier.MetadataIDentifier) (string, error) {
return "definition", nil
}
......@@ -56,7 +56,7 @@ func TestDubboInvokerInvoke(t *testing.T) {
// Call
res := invoker.Invoke(context.Background(), inv)
assert.NoError(t, res.Error())
assert.Equal(t, User{Id: "1", Name: "username"}, *res.Result().(*User))
assert.Equal(t, User{ID: "1", Name: "username"}, *res.Result().(*User))
// CallOneway
inv.SetAttachments(constant.ASYNC_KEY, "true")
......@@ -69,7 +69,7 @@ func TestDubboInvokerInvoke(t *testing.T) {
inv.SetCallBack(func(response common.CallbackResponse) {
r := response.(remoting.AsyncCallbackResponse)
rst := *r.Reply.(*remoting.Response).Result.(*protocol.RPCResult)
assert.Equal(t, User{Id: "1", Name: "username"}, *(rst.Rest.(*User)))
assert.Equal(t, User{ID: "1", Name: "username"}, *(rst.Rest.(*User)))
// assert.Equal(t, User{ID: "1", Name: "username"}, *r.Reply.(*Response).reply.(*User))
lock.Unlock()
})
......@@ -164,7 +164,7 @@ func InitTest(t *testing.T) (protocol.Protocol, *common.URL) {
type (
User struct {
Id string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
}
......@@ -179,19 +179,19 @@ func (u *UserProvider) GetBigPkg(ctx context.Context, req []interface{}, rsp *Us
// use chinese for test
argBuf.WriteString("击鼓其镗,踊跃用兵。土国城漕,我独南行。从孙子仲,平陈与宋。不我以归,忧心有忡。爰居爰处?爰丧其马?于以求之?于林之下。死生契阔,与子成说。执子之手,与子偕老。于嗟阔兮,不我活兮。于嗟洵兮,不我信兮。")
}
rsp.Id = argBuf.String()
rsp.ID = argBuf.String()
rsp.Name = argBuf.String()
return nil
}
func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User) error {
rsp.Id = req[0].(string)
rsp.ID = req[0].(string)
rsp.Name = req[1].(string)
return nil
}
func (u *UserProvider) GetUser0(id string, k *User, name string) (User, error) {
return User{Id: id, Name: name}, nil
return User{ID: id, Name: name}, nil
}
func (u *UserProvider) GetUser1() error {
......@@ -203,23 +203,23 @@ func (u *UserProvider) GetUser2() error {
}
func (u *UserProvider) GetUser3(rsp *[]interface{}) error {
*rsp = append(*rsp, User{Id: "1", Name: "username"})
*rsp = append(*rsp, User{ID: "1", Name: "username"})
return nil
}
func (u *UserProvider) GetUser4(ctx context.Context, req []interface{}) ([]interface{}, error) {
return []interface{}{User{Id: req[0].([]interface{})[0].(string), Name: req[0].([]interface{})[1].(string)}}, nil
return []interface{}{User{ID: req[0].([]interface{})[0].(string), Name: req[0].([]interface{})[1].(string)}}, nil
}
func (u *UserProvider) GetUser5(ctx context.Context, req []interface{}) (map[interface{}]interface{}, error) {
return map[interface{}]interface{}{"key": User{Id: req[0].(map[interface{}]interface{})["id"].(string), Name: req[0].(map[interface{}]interface{})["name"].(string)}}, nil
return map[interface{}]interface{}{"key": User{ID: req[0].(map[interface{}]interface{})["id"].(string), Name: req[0].(map[interface{}]interface{})["name"].(string)}}, nil
}
func (u *UserProvider) GetUser6(id int64) (*User, error) {
if id == 0 {
return nil, nil
}
return &User{Id: "1"}, nil
return &User{ID: "1"}, nil
}
func (u *UserProvider) Reference() string {
......
......@@ -199,7 +199,7 @@ func TestHessianCodec_ReadAttachments(t *testing.T) {
body := &DubboResponse{
RspObj: &CaseB{A: "A", B: CaseA{A: "a", B: 1, C: Case{A: "c", B: 2}}},
Exception: nil,
Attachments: map[string]interface{}{DUBBO_VERSION_KEY: "2.6.4", "att": AttachTestObject{Id: 23, Name: "haha"}},
Attachments: map[string]interface{}{DUBBO_VERSION_KEY: "2.6.4", "att": AttachTestObject{ID: 23, Name: "haha"}},
}
resp, err := doTestHessianEncodeHeader(t, PackageResponse, Response_OK, body)
assert.NoError(t, err)
......@@ -217,14 +217,14 @@ func TestHessianCodec_ReadAttachments(t *testing.T) {
attrs, err := codecR2.ReadAttachments()
assert.NoError(t, err)
assert.Equal(t, "2.6.4", attrs[DUBBO_VERSION_KEY])
assert.Equal(t, AttachTestObject{Id: 23, Name: "haha"}, *(attrs["att"].(*AttachTestObject)))
assert.NotEqual(t, AttachTestObject{Id: 24, Name: "nohaha"}, *(attrs["att"].(*AttachTestObject)))
assert.Equal(t, AttachTestObject{ID: 23, Name: "haha"}, *(attrs["att"].(*AttachTestObject)))
assert.NotEqual(t, AttachTestObject{ID: 24, Name: "nohaha"}, *(attrs["att"].(*AttachTestObject)))
t.Log(attrs)
}
type AttachTestObject struct {
Id int32
ID int32
Name string `dubbo:"name"`
}
......
......@@ -39,7 +39,7 @@ import (
type (
User struct {
Id string `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
}
......@@ -82,7 +82,7 @@ func TestHTTPClientCall(t *testing.T) {
reply := &User{}
err = client.Call(ctx, url, req, reply)
assert.NoError(t, err)
assert.Equal(t, "1", reply.Id)
assert.Equal(t, "1", reply.ID)
assert.Equal(t, "username", reply.Name)
// call GetUser0
......@@ -95,7 +95,7 @@ func TestHTTPClientCall(t *testing.T) {
reply = &User{}
err = client.Call(ctx, url, req, reply)
assert.NoError(t, err)
assert.Equal(t, "1", reply.Id)
assert.Equal(t, "1", reply.ID)
assert.Equal(t, "username", reply.Name)
// call GetUser1
......@@ -120,7 +120,7 @@ func TestHTTPClientCall(t *testing.T) {
reply1 := []User{}
err = client.Call(ctx, url, req, &reply1)
assert.NoError(t, err)
assert.Equal(t, User{Id: "1", Name: "username"}, reply1[0])
assert.Equal(t, User{ID: "1", Name: "username"}, reply1[0])
// call GetUser3
ctx = context.WithValue(context.Background(), constant.DUBBOGO_CTX_KEY, map[string]string{
......@@ -132,7 +132,7 @@ func TestHTTPClientCall(t *testing.T) {
reply1 = []User{}
err = client.Call(ctx, url, req, &reply1)
assert.NoError(t, err)
assert.Equal(t, User{Id: "1", Name: "username"}, reply1[0])
assert.Equal(t, User{ID: "1", Name: "username"}, reply1[0])
// call GetUser4
ctx = context.WithValue(context.Background(), constant.DUBBOGO_CTX_KEY, map[string]string{
......@@ -144,7 +144,7 @@ func TestHTTPClientCall(t *testing.T) {
reply = &User{}
err = client.Call(ctx, url, req, reply)
assert.NoError(t, err)
assert.Equal(t, &User{Id: "", Name: ""}, reply)
assert.Equal(t, &User{ID: "", Name: ""}, reply)
ctx = context.WithValue(context.Background(), constant.DUBBOGO_CTX_KEY, map[string]string{
"X-Proxy-ID": "dubbogo",
......@@ -159,20 +159,20 @@ func TestHTTPClientCall(t *testing.T) {
reply = &User{}
err = client.Call(ctx, url, req, reply)
assert.NoError(t, err)
assert.Equal(t, &User{Id: "1", Name: ""}, reply)
assert.Equal(t, &User{ID: "1", Name: ""}, reply)
// destroy
proto.Destroy()
}
func (u *UserProvider) GetUser(ctx context.Context, req []interface{}, rsp *User) error {
rsp.Id = req[0].(string)
rsp.ID = req[0].(string)
rsp.Name = req[1].(string)
return nil
}
func (u *UserProvider) GetUser0(id string, k *User, name string) (User, error) {
return User{Id: id, Name: name}, nil
return User{ID: id, Name: name}, nil
}
func (u *UserProvider) GetUser1() error {
......@@ -180,19 +180,19 @@ func (u *UserProvider) GetUser1() error {
}
func (u *UserProvider) GetUser2(ctx context.Context, req []interface{}, rsp *[]User) error {
*rsp = append(*rsp, User{Id: req[0].(string), Name: req[1].(string)})
*rsp = append(*rsp, User{ID: req[0].(string), Name: req[1].(string)})
return nil
}
func (u *UserProvider) GetUser3(ctx context.Context, req []interface{}) ([]User, error) {
return []User{{Id: req[0].(string), Name: req[1].(string)}}, nil
return []User{{ID: req[0].(string), Name: req[1].(string)}}, nil
}
func (u *UserProvider) GetUser4(id float64) (*User, error) {
if id == 0 {
return nil, nil
}
return &User{Id: "1"}, nil
return &User{ID: "1"}, nil
}
func (u *UserProvider) Reference() string {
......
......@@ -51,7 +51,7 @@ func (ji *JsonrpcInvoker) Invoke(ctx context.Context, invocation protocol.Invoca
url := ji.GetUrl()
req := ji.client.NewRequest(url, inv.MethodName(), inv.Arguments())
ctxNew := context.WithValue(ctx, constant.DUBBOGO_CTX_KEY, map[string]string{
"X-Proxy-Id": "dubbogo",
"X-Proxy-ID": "dubbogo",
"X-Services": url.Path,
"X-Method": inv.MethodName(),
})
......
......@@ -63,7 +63,7 @@ func TestJsonrpcInvokerInvoke(t *testing.T) {
invocation.WithReply(user)))
assert.NoError(t, res.Error())
assert.Equal(t, User{Id: "1", Name: "username"}, *res.Result().(*User))
assert.Equal(t, User{ID: "1", Name: "username"}, *res.Result().(*User))
// destroy
proto.Destroy()
......
......@@ -69,7 +69,7 @@ func (c *RestProviderConfig) UnmarshalYAML(unmarshal func(interface{}) error) er
// nolint
type RestServiceConfig struct {
InterfaceName string `required:"true" yaml:"interface" json:"interface,omitempty" property:"interface"`
Url string `yaml:"url" json:"url,omitempty" property:"url"`
URL string `yaml:"url" json:"url,omitempty" property:"url"`
Path string `yaml:"rest_path" json:"rest_path,omitempty" property:"rest_path"`
Produces string `yaml:"rest_produces" json:"rest_produces,omitempty" property:"rest_produces"`
Consumes string `yaml:"rest_consumes" json:"rest_consumes,omitempty" property:"rest_consumes"`
......@@ -96,7 +96,7 @@ func (c *RestServiceConfig) UnmarshalYAML(unmarshal func(interface{}) error) err
type RestMethodConfig struct {
InterfaceName string
MethodName string `required:"true" yaml:"name" json:"name,omitempty" property:"name"`
Url string `yaml:"url" json:"url,omitempty" property:"url"`
URL string `yaml:"url" json:"url,omitempty" property:"url"`
Path string `yaml:"rest_path" json:"rest_path,omitempty" property:"rest_path"`
Produces string `yaml:"rest_produces" json:"rest_produces,omitempty" property:"rest_produces"`
Consumes string `yaml:"rest_consumes" json:"rest_consumes,omitempty" property:"rest_consumes"`
......
......@@ -172,14 +172,14 @@ func TestRestInvokerInvoke(t *testing.T) {
invocation.WithArguments([]interface{}{1, int32(23), "username", "application/json"}), invocation.WithReply(user))
res := invoker.Invoke(context.Background(), inv)
assert.NoError(t, res.Error())
assert.Equal(t, User{Id: 1, Age: int32(23), Name: "username"}, *res.Result().(*User))
assert.Equal(t, User{ID: 1, Age: int32(23), Name: "username"}, *res.Result().(*User))
now := time.Now()
inv = invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("GetUserOne"),
invocation.WithArguments([]interface{}{&User{1, &now, int32(23), "username"}}), invocation.WithReply(user))
res = invoker.Invoke(context.Background(), inv)
assert.NoError(t, res.Error())
assert.NotNil(t, res.Result())
assert.Equal(t, 1, res.Result().(*User).Id)
assert.Equal(t, 1, res.Result().(*User).ID)
assert.Equal(t, now.Unix(), res.Result().(*User).Time.Unix())
assert.Equal(t, int32(23), res.Result().(*User).Age)
assert.Equal(t, "username", res.Result().(*User).Name)
......
......@@ -130,7 +130,7 @@ func (p *UserProvider) Reference() string {
func (p *UserProvider) GetUser(ctx context.Context, id int, age int32, name string, contentType string) (*User, error) {
return &User{
Id: id,
ID: id,
Time: nil,
Age: age,
Name: name,
......@@ -168,7 +168,7 @@ func (p *UserProvider) GetUserFive(ctx context.Context, user []interface{}) (*Us
}
type User struct {
Id int
ID int
Time *time.Time
Age int32
Name string
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment