-
Notifications
You must be signed in to change notification settings - Fork 930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add: DelegateMetadataReport & RemoteMetadataService #505
Changes from 5 commits
b87dbe2
73f21fa
f7dd531
9788244
0048609
235edf5
c312cc8
0d78b2a
c024ce1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,13 +19,21 @@ package definition | |
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
import ( | ||
"github.com/apache/dubbo-go/common" | ||
"github.com/apache/dubbo-go/common/constant" | ||
) | ||
|
||
// ServiceDefinition is a interface of service's definition | ||
hxmhlt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type ServiceDefiner interface { | ||
ToBytes() ([]byte, error) | ||
} | ||
|
||
// ServiceDefinition is the describer of service definition | ||
type ServiceDefinition struct { | ||
CanonicalName string | ||
|
@@ -34,6 +42,36 @@ type ServiceDefinition struct { | |
Types []TypeDefinition | ||
} | ||
|
||
func (def ServiceDefinition) ToBytes() ([]byte, error) { | ||
hxmhlt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return json.Marshal(def) | ||
} | ||
|
||
func (def ServiceDefinition) String() string { | ||
var methodStr strings.Builder | ||
for _, m := range def.Methods { | ||
var paramType strings.Builder | ||
for _, p := range m.ParameterTypes { | ||
paramType.WriteString(fmt.Sprintf("{type:%v}", p)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fmt.Fprintf(paramType, "{type:%v}", p) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you wanna got its type, u should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
type is just the variable's name. Not reflect.type meaning. |
||
} | ||
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)) | ||
} | ||
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)) | ||
} | ||
return fmt.Sprintf("{canonicalName:%v, codeSource:%v, methods:[%v], types:[%v]}", def.CanonicalName, def.CodeSource, methodStr.String(), types.String()) | ||
} | ||
|
||
// FullServiceDefinition is the describer of service definition with parameters | ||
type FullServiceDefinition struct { | ||
ServiceDefinition | ||
Params map[string]string | ||
} | ||
|
||
// MethodDefinition is the describer of method definition | ||
type MethodDefinition struct { | ||
Name string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package definition | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
import ( | ||
"github.com/apache/dubbo-go/common" | ||
"github.com/apache/dubbo-go/common/constant" | ||
) | ||
|
||
func TestBuildServiceDefinition(t *testing.T) { | ||
serviceName := "com.ikurento.user.UserProvider" | ||
group := "group1" | ||
version := "0.0.1" | ||
protocol := "dubbo" | ||
beanName := "UserProvider" | ||
url, err := common.NewURL(fmt.Sprintf( | ||
"%v://127.0.0.1:20000/com.ikurento.user.UserProvider1?anyhost=true&"+ | ||
"application=BDTService&category=providers&default.timeout=10000&dubbo=dubbo-provider-golang-1.0.0&"+ | ||
"environment=dev&interface=%v&ip=192.168.56.1&methods=GetUser&module=dubbogo+user-info+server&org=ikurento.com&"+ | ||
"owner=ZX&pid=1447&revision=0.0.1&side=provider&timeout=3000×tamp=1556509797245&group=%v&version=%v&bean.name=%v", | ||
protocol, serviceName, group, version, beanName)) | ||
assert.NoError(t, err) | ||
_, err = common.ServiceMap.Register(serviceName, protocol, &UserProvider{}) | ||
assert.NoError(t, err) | ||
service := common.ServiceMap.GetService(url.Protocol, url.GetParam(constant.BEAN_NAME_KEY, url.Service())) | ||
sd := BuildServiceDefinition(*service, url) | ||
assert.Equal(t, "{canonicalName:com.ikurento.user.UserProvider, codeSource:, methods:[{name:GetUser,parameterTypes:[{type:slice}],returnType:ptr,params:[] }], types:[]}", sd.String()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it just used for test case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think it is a problem. Dubbo Java has many similar practices. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If just for test ,then i think that is a problem, because it can be use out of test case . what do you think ? @flycash @fangyincheng @AlexStocks |
||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package definition | ||
|
||
import ( | ||
"context" | ||
"time" | ||
) | ||
|
||
type User struct { | ||
Id string | ||
Name string | ||
Age int32 | ||
Time time.Time | ||
} | ||
|
||
type UserProvider struct { | ||
} | ||
|
||
func (u *UserProvider) GetUser(ctx context.Context, req []interface{}) (*User, error) { | ||
rsp := User{"A001", "Alex Stocks", 18, time.Now()} | ||
return &rsp, nil | ||
} | ||
|
||
func (u *UserProvider) Reference() string { | ||
return "UserProvider" | ||
} | ||
|
||
func (u User) JavaClassName() string { | ||
return "com.ikurento.user.User" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why import redis?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I import go-cron lib and redis lib is imported.