Skip to content

Commit

Permalink
Merge pull request #500 from flycash/2.7.5
Browse files Browse the repository at this point in the history
Merge develop to 2.7.5
  • Loading branch information
zouyx authored May 2, 2020
2 parents 9b41e95 + 59365ec commit 6a558d8
Show file tree
Hide file tree
Showing 31 changed files with 488 additions and 313 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Apache License, Version 2.0

## Release note ##

[v1.4.0-rc1 - Mar 12, 2020](https://github.com/apache/dubbo-go/releases/tag/v1.4.0-rc1)
[v1.4.0 - Mar 17, 2020](https://github.com/apache/dubbo-go/releases/tag/v1.4.0)

[v1.3.0 - Mar 1, 2020](https://github.com/apache/dubbo-go/releases/tag/v1.3.0)

Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Apache License, Version 2.0

## 发布日志 ##

[v1.4.0-rc1 - 2020年3月12日](https://github.com/apache/dubbo-go/releases/tag/v1.4.0-rc1)
[v1.4.0 - 2020年3月17日](https://github.com/apache/dubbo-go/releases/tag/v1.4.0)

[v1.3.0 - 2020年3月1日](https://github.com/apache/dubbo-go/releases/tag/v1.3.0)

Expand Down
41 changes: 41 additions & 0 deletions common/extension/registry_directory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 extension

import (
"github.com/apache/dubbo-go/cluster"
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/registry"
)

type registryDirectory func(url *common.URL, registry registry.Registry) (cluster.Directory, error)

var defaultRegistry registryDirectory

// SetDefaultRegistryDirectory ...
func SetDefaultRegistryDirectory(v registryDirectory) {
defaultRegistry = v
}

// GetDefaultRegistryDirectory ...
func GetDefaultRegistryDirectory(config *common.URL, registry registry.Registry) (cluster.Directory, error) {
if defaultRegistry == nil {
panic("registry directory is not existing, make sure you have import the package.")
}
return defaultRegistry(config, registry)
}
7 changes: 3 additions & 4 deletions common/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
typError = reflect.Zero(reflect.TypeOf((*error)(nil)).Elem()).Type()
)

// NewProxy ...
// NewProxy create service proxy.
func NewProxy(invoke protocol.Invoker, callBack interface{}, attachments map[string]string) *Proxy {
return &Proxy{
invoke: invoke,
Expand All @@ -59,7 +59,6 @@ func NewProxy(invoke protocol.Invoker, callBack interface{}, attachments map[str
// type XxxProvider struct {
// Yyy func(ctx context.Context, args []interface{}, rsp *Zzz) error
// }

func (p *Proxy) Implement(v common.RPCService) {

// check parameters, incoming interface must be a elem's pointer.
Expand Down Expand Up @@ -202,12 +201,12 @@ func (p *Proxy) Implement(v common.RPCService) {

}

// Get ...
// Get get rpc service instance.
func (p *Proxy) Get() common.RPCService {
return p.rpc
}

// GetCallback ...
// GetCallback get callback.
func (p *Proxy) GetCallback() interface{} {
return p.callBack
}
2 changes: 1 addition & 1 deletion common/proxy/proxy_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/apache/dubbo-go/protocol"
)

// ProxyFactory ...
// ProxyFactory interface.
type ProxyFactory interface {
GetProxy(invoker protocol.Invoker, url *common.URL) *Proxy
GetAsyncProxy(invoker protocol.Invoker, callBack interface{}, url *common.URL) *Proxy
Expand Down
23 changes: 11 additions & 12 deletions common/rpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ type AsyncCallback func(response CallbackResponse)
// return map[string][string]{}
// }
const (
// METHOD_MAPPER ...
METHOD_MAPPER = "MethodMapper"
)

Expand All @@ -68,7 +67,7 @@ var (
// because Typeof takes an empty interface value. This is annoying.
typeOfError = reflect.TypeOf((*error)(nil)).Elem()

// ServiceMap ...
// ServiceMap store description of service.
// todo: lowerecas?
ServiceMap = &serviceMap{
serviceMap: make(map[string]map[string]*Service),
Expand All @@ -80,35 +79,35 @@ var (
// info of method
//////////////////////////

// MethodType ...
// MethodType is description of service method.
type MethodType struct {
method reflect.Method
ctxType reflect.Type // request context
argsType []reflect.Type // args except ctx, include replyType if existing
replyType reflect.Type // return value, otherwise it is nil
}

// Method ...
// Method get @m.method.
func (m *MethodType) Method() reflect.Method {
return m.method
}

// CtxType ...
// CtxType get @m.ctxType.
func (m *MethodType) CtxType() reflect.Type {
return m.ctxType
}

// ArgsType ...
// ArgsType get @m.argsType.
func (m *MethodType) ArgsType() []reflect.Type {
return m.argsType
}

// ReplyType ...
// ReplyType get @m.replyType.
func (m *MethodType) ReplyType() reflect.Type {
return m.replyType
}

// SuiteContext ...
// SuiteContext tranfer @ctx to reflect.Value type or get it from @m.ctxType.
func (m *MethodType) SuiteContext(ctx context.Context) reflect.Value {
if contextv := reflect.ValueOf(ctx); contextv.IsValid() {
return contextv
Expand All @@ -120,15 +119,15 @@ func (m *MethodType) SuiteContext(ctx context.Context) reflect.Value {
// info of service interface
//////////////////////////

// Service ...
// Service is description of service
type Service struct {
name string
rcvr reflect.Value
rcvrType reflect.Type
methods map[string]*MethodType
}

// Method ...
// Method get @s.methods.
func (s *Service) Method() map[string]*MethodType {
return s.methods
}
Expand All @@ -138,12 +137,12 @@ func (s *Service) Name() string {
return s.name
}

// RcvrType ...
// RcvrType get @s.rcvrType.
func (s *Service) RcvrType() reflect.Type {
return s.rcvrType
}

// Rcvr ...
// Rcvr get @s.rcvr.
func (s *Service) Rcvr() reflect.Value {
return s.rcvr
}
Expand Down
71 changes: 42 additions & 29 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func NewURLWithOptions(opts ...option) *URL {
// NewURL will create a new url
// the urlString should not be empty
func NewURL(urlString string, opts ...option) (URL, error) {

var (
err error
rawUrlString string
Expand Down Expand Up @@ -249,7 +248,7 @@ func NewURL(urlString string, opts ...option) (URL, error) {
return s, nil
}

// URLEqual ...
// URLEqual judge @url and @c is equal or not.
func (c URL) URLEqual(url URL) bool {
c.Ip = ""
c.Port = ""
Expand All @@ -265,17 +264,19 @@ func (c URL) URLEqual(url URL) bool {
} else if urlGroup == constant.ANY_VALUE {
urlKey = strings.Replace(urlKey, "group=*", "group="+cGroup, 1)
}

// 1. protocol, username, password, ip, port, service name, group, version should be equal
if cKey != urlKey {
return false
}

// 2. if url contains enabled key, should be true, or *
if url.GetParam(constant.ENABLED_KEY, "true") != "true" && url.GetParam(constant.ENABLED_KEY, "") != constant.ANY_VALUE {
return false
}

//TODO :may need add interface key any value condition
if !isMatchCategory(url.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY), c.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY)) {
return false
}
return true
return isMatchCategory(url.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY), c.GetParam(constant.CATEGORY_KEY, constant.DEFAULT_CATEGORY))
}

func isMatchCategory(category1 string, category2 string) bool {
Expand Down Expand Up @@ -313,10 +314,9 @@ func (c URL) Key() string {
"%s://%s:%s@%s:%s/?interface=%s&group=%s&version=%s",
c.Protocol, c.Username, c.Password, c.Ip, c.Port, c.Service(), c.GetParam(constant.GROUP_KEY, ""), c.GetParam(constant.VERSION_KEY, ""))
return buildString
//return c.ServiceKey()
}

// ServiceKey ...
// ServiceKey get a unique key of a service.
func (c URL) ServiceKey() string {
intf := c.GetParam(constant.INTERFACE_KEY, strings.TrimPrefix(c.Path, "/"))
if intf == "" {
Expand Down Expand Up @@ -409,12 +409,12 @@ func (c *URL) RangeParams(f func(key, value string) bool) {

// GetParam ...
func (c URL) GetParam(s string, d string) string {
var r string
c.paramsLock.RLock()
if r = c.params.Get(s); len(r) == 0 {
defer c.paramsLock.RUnlock()
r := c.params.Get(s)
if len(r) == 0 {
r = d
}
c.paramsLock.RUnlock()
return r
}

Expand Down Expand Up @@ -454,33 +454,26 @@ func (c URL) GetRawParam(key string) string {

// GetParamBool ...
func (c URL) GetParamBool(s string, d bool) bool {

var r bool
var err error
if r, err = strconv.ParseBool(c.GetParam(s, "")); err != nil {
r, err := strconv.ParseBool(c.GetParam(s, ""))
if err != nil {
return d
}
return r
}

// GetParamInt ...
func (c URL) GetParamInt(s string, d int64) int64 {
var r int
var err error

if r, err = strconv.Atoi(c.GetParam(s, "")); r == 0 || err != nil {
r, err := strconv.Atoi(c.GetParam(s, ""))
if r == 0 || err != nil {
return d
}
return int64(r)
}

// GetMethodParamInt ...
func (c URL) GetMethodParamInt(method string, key string, d int64) int64 {
var r int
var err error
c.paramsLock.RLock()
defer c.paramsLock.RUnlock()
if r, err = strconv.Atoi(c.GetParam("methods."+method+"."+key, "")); r == 0 || err != nil {
r, err := strconv.Atoi(c.GetParam("methods."+method+"."+key, ""))
if r == 0 || err != nil {
return d
}
return int64(r)
Expand All @@ -492,14 +485,13 @@ func (c URL) GetMethodParamInt64(method string, key string, d int64) int64 {
if r == math.MinInt64 {
return c.GetParamInt(key, d)
}

return r
}

// GetMethodParam ...
func (c URL) GetMethodParam(method string, key string, d string) string {
var r string
if r = c.GetParam("methods."+method+"."+key, ""); r == "" {
r := c.GetParam("methods."+method+"."+key, "")
if r == "" {
r = d
}
return r
Expand Down Expand Up @@ -530,7 +522,6 @@ func (c *URL) SetParams(m url.Values) {

// ToMap transfer URL to Map
func (c URL) ToMap() map[string]string {

paramsMap := make(map[string]string)

c.RangeParams(func(key, value string) bool {
Expand Down Expand Up @@ -615,8 +606,30 @@ func (c *URL) Clone() *URL {
return newUrl
}

// Copy url based on the reserved parameters' keys.
func (c *URL) CloneWithParams(reserveParams []string) *URL {
params := url.Values{}
for _, reserveParam := range reserveParams {
v := c.GetParam(reserveParam, "")
if len(v) != 0 {
params.Set(reserveParam, v)
}
}

return NewURLWithOptions(
WithProtocol(c.Protocol),
WithUsername(c.Username),
WithPassword(c.Password),
WithIp(c.Ip),
WithPort(c.Port),
WithPath(c.Path),
WithMethods(c.Methods),
WithParams(params),
)
}

func mergeNormalParam(mergedUrl *URL, referenceUrl *URL, paramKeys []string) []func(method string) {
var methodConfigMergeFcn = []func(method string){}
methodConfigMergeFcn := make([]func(method string), 0, len(paramKeys))
for _, paramKey := range paramKeys {
if v := referenceUrl.GetParam(paramKey, ""); len(v) > 0 {
mergedUrl.SetParam(paramKey, v)
Expand Down
Loading

0 comments on commit 6a558d8

Please sign in to comment.