Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
DMwangnima committed Nov 29, 2023
2 parents 8203523 + 778c1bd commit f91ee63
Show file tree
Hide file tree
Showing 26 changed files with 326 additions and 44 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/protoc-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Protoc-gen-go-triple Release

on:
release:
types: [published]

jobs:
release:
permissions:
contents: write

name: Release cmd/protoc-gen-go-triple
runs-on: ubuntu-latest
if: startsWith(github.event.release.tag_name, 'cmd/protoc-gen-go-triple/')
strategy:
matrix:
goos: [linux, darwin, windows]
goarch: [386, amd64, arm64]
exclude:
- goos: darwin
goarch: 386

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2

- name: Download dependencies
run: |
cd cmd/protoc-gen-go-triple
go mod download
- name: Prepare build directory
run: |
mkdir -p build/
cp README.md build/
cp LICENSE build/
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
cd cmd/protoc-gen-go-triple
go build -trimpath -o $GITHUB_WORKSPACE/build
- name: Create package
id: package
run: |
PACKAGE_NAME=protoc-gen-go-triple.${GITHUB_REF#refs/tags/cmd/protoc-gen-go-triple/}.${{ matrix.goos }}.${{ matrix.goarch }}.tar.gz
tar -czvf $PACKAGE_NAME -C build .
echo "name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT
- name: Upload asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./${{ steps.package.outputs.name }}
asset_name: ${{ steps.package.outputs.name }}
asset_content_type: application/gzip
4 changes: 4 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,7 @@
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.

For the package protocol/triple:

This package contains a modified portion of 'connect-go', a family of libraries for building gRPC-compatible HTTP APIs also under the "Apache License 2.0" license, see https://github.com/bufbuild/connect-go/blob/main/LICENSE.
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Apache Dubbo-go
Copyright 2018-2022 The Apache Software Foundation
Copyright 2018-2023 The Apache Software Foundation

This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
2 changes: 1 addition & 1 deletion client/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func processURL(ref *global.ReferenceConfig, regsCompat map[string]*config.Regis
}
// replace params of serviceURL with params of cfgUrl
// other stuff, e.g. IP, port, etc., are same as serviceURL
newURL := common.MergeURL(serviceURL, cfgURL)
newURL := serviceURL.MergeURL(cfgURL)
newURL.AddParam("peer", "true")
urls = append(urls, newURL)
}
Expand Down
5 changes: 5 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ type ClientInfo struct {
Meta map[string]interface{}
}

type ClientDefinition struct {
Svc interface{}
Info *ClientInfo
}

// InterfaceName/group/version /ReferenceConfig
type Connection struct {
refOpts *ReferenceOptions
Expand Down
10 changes: 8 additions & 2 deletions client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ func (refOpts *ReferenceOptions) init(opts ...ReferenceOption) error {
}

// init protocol
if ref.Protocol == "" && refOpts.Consumer != nil {
ref.Protocol = refOpts.Consumer.Protocol
if ref.Protocol == "" {
ref.Protocol = "tri"
if refOpts.Consumer != nil && refOpts.Consumer.Protocol != "" {
ref.Protocol = refOpts.Consumer.Protocol
}
}

// init serialization
Expand Down Expand Up @@ -310,6 +313,9 @@ func WithAsync() ReferenceOption {

func WithParams(params map[string]string) ReferenceOption {
return func(opts *ReferenceOptions) {
if len(params) <= 0 {
return
}
opts.Reference.Params = params
}
}
Expand Down
9 changes: 0 additions & 9 deletions client/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1157,15 +1157,6 @@ func TestWithRequestTimeout(t *testing.T) {
assert.Equal(t, "6s", refOpts.Reference.RequestTimeout)
},
},
// todo(DMwangnima): consider whether this default timeout is ideal
{
desc: "default RequestTimeout",
opts: []ReferenceOption{},
verify: func(t *testing.T, refOpts *ReferenceOptions, err error) {
assert.Nil(t, err)
assert.Equal(t, "3s", refOpts.Reference.RequestTimeout)
},
},
}
processReferenceOptionsInitCases(t, cases)
}
Expand Down
1 change: 1 addition & 0 deletions common/constant/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package constant

// nolint
const (
DefaultDubboApp = "dubbo.io"
ConfigFileEnvKey = "DUBBO_GO_CONFIG_PATH" // key of environment variable dubbogo configure file path
AppLogConfFile = "AppLogConfFile"
PodNameEnvKey = "POD_NAME"
Expand Down
35 changes: 18 additions & 17 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,20 +772,20 @@ func (c *URL) ToMap() map[string]string {
// TODO configuration merge, in the future , the configuration center's config should merge too.

// MergeURL will merge those two URL
// the result is based on serviceURL, and the key which si only contained in referenceURL
// the result is based on c, and the key which si only contained in anotherUrl
// will be added into result.
// for example, if serviceURL contains params (a1->v1, b1->v2) and referenceURL contains params(a2->v3, b1 -> v4)
// for example, if c contains params (a1->v1, b1->v2) and anotherUrl contains params(a2->v3, b1 -> v4)
// the params of result will be (a1->v1, b1->v2, a2->v3).
// You should notice that the value of b1 is v2, not v4
// except constant.LoadbalanceKey, constant.ClusterKey, constant.RetriesKey, constant.TimeoutKey.
// due to URL is not thread-safe, so this method is not thread-safe
func MergeURL(serviceURL *URL, referenceURL *URL) *URL {
func (c *URL) MergeURL(anotherUrl *URL) *URL {
// After Clone, it is a new URL that there is no thread safe issue.
mergedURL := serviceURL.Clone()
mergedURL := c.Clone()
params := mergedURL.GetParams()
// iterator the referenceURL if serviceURL not have the key ,merge in
// referenceURL usually will not changed. so change RangeParams to GetParams to avoid the string value copy.// Group get group
for key, value := range referenceURL.GetParams() {
// iterator the anotherUrl if c not have the key ,merge in
// anotherUrl usually will not changed. so change RangeParams to GetParams to avoid the string value copy.// Group get group
for key, value := range anotherUrl.GetParams() {
if _, ok := mergedURL.GetNonDefaultParam(key); !ok {
if len(value) > 0 {
params[key] = value
Expand All @@ -796,35 +796,36 @@ func MergeURL(serviceURL *URL, referenceURL *URL) *URL {
}

// remote timestamp
if v, ok := serviceURL.GetNonDefaultParam(constant.TimestampKey); !ok {
if v, ok := c.GetNonDefaultParam(constant.TimestampKey); !ok {
params[constant.RemoteTimestampKey] = []string{v}
params[constant.TimestampKey] = []string{referenceURL.GetParam(constant.TimestampKey, "")}
params[constant.TimestampKey] = []string{anotherUrl.GetParam(constant.TimestampKey, "")}
}

// finally execute methodConfigMergeFcn
mergedURL.Methods = make([]string, len(referenceURL.Methods))
for i, method := range referenceURL.Methods {
mergedURL.Methods = make([]string, len(anotherUrl.Methods))
for i, method := range anotherUrl.Methods {
for _, paramKey := range []string{constant.LoadbalanceKey, constant.ClusterKey, constant.RetriesKey, constant.TimeoutKey} {
if v := referenceURL.GetParam(paramKey, ""); len(v) > 0 {
if v := anotherUrl.GetParam(paramKey, ""); len(v) > 0 {
params[paramKey] = []string{v}
}

methodsKey := "methods." + method + "." + paramKey
//if len(mergedURL.GetParam(methodsKey, "")) == 0 {
if v := referenceURL.GetParam(methodsKey, ""); len(v) > 0 {
if v := anotherUrl.GetParam(methodsKey, ""); len(v) > 0 {
params[methodsKey] = []string{v}
}
//}
mergedURL.Methods[i] = method
}
}

// merge attributes
if mergedURL.attributes == nil {
mergedURL.attributes = make(map[string]interface{}, len(referenceURL.attributes))
mergedURL.attributes = make(map[string]interface{}, len(anotherUrl.attributes))
}
for attrK, attrV := range referenceURL.attributes {
mergedURL.attributes[attrK] = attrV
for attrK, attrV := range anotherUrl.attributes {
if _, ok := mergedURL.GetAttribute(attrK); !ok {
mergedURL.attributes[attrK] = attrV
}
}
// In this way, we will raise some performance.
mergedURL.ReplaceParams(params)
Expand Down
2 changes: 1 addition & 1 deletion common/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func TestMergeUrl(t *testing.T) {
referenceUrl, _ := NewURL("mock1://127.0.0.1:1111", WithParams(referenceUrlParams), WithMethods([]string{"testMethod"}))
serviceUrl, _ := NewURL("mock2://127.0.0.1:20000", WithParams(serviceUrlParams))

mergedUrl := MergeURL(serviceUrl, referenceUrl)
mergedUrl := serviceUrl.MergeURL(referenceUrl)
assert.Equal(t, "random", mergedUrl.GetParam(constant.ClusterKey, ""))
assert.Equal(t, "1", mergedUrl.GetParam("test2", ""))
assert.Equal(t, "1", mergedUrl.GetParam("test3", ""))
Expand Down
3 changes: 3 additions & 0 deletions config/application_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (ac *ApplicationConfig) Init() error {
if err := ac.check(); err != nil {
return err
}
if ac.Name == "" {
ac.Name = constant.DefaultDubboApp
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion config/reference_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (rc *ReferenceConfig) Refer(srv interface{}) {
}
// replace params of serviceURL with params of cfgUrl
// other stuff, e.g. IP, port, etc., are same as serviceURL
newURL := common.MergeURL(serviceURL, cfgURL)
newURL := serviceURL.MergeURL(cfgURL)
newURL.AddParam("peer", "true")
rc.urls = append(rc.urls, newURL)
}
Expand Down
92 changes: 92 additions & 0 deletions dubbo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,29 @@
package dubbo

import (
"sync"
)

import (
"github.com/dubbogo/gost/log/logger"

"github.com/pkg/errors"
)

import (
"dubbo.apache.org/dubbo-go/v3/client"
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/server"
)

var (
consumerServices = map[string]*client.ClientDefinition{}
conLock sync.RWMutex
providerServices = map[string]*server.ServiceDefinition{}
proLock sync.RWMutex
startOnce sync.Once
)

// Instance is the highest layer conception that user could touch. It is mapped from RootConfig.
// When users want to inject global configurations and configure common modules for client layer
// and server layer, user-side code would be like this:
Expand Down Expand Up @@ -156,3 +171,80 @@ func (ins *Instance) NewServer(opts ...server.ServerOption) (*server.Server, err
}
return srv, nil
}

func (ins *Instance) start() (err error) {
startOnce.Do(func() {
if err = ins.loadConsumer(); err != nil {
return
}
if err = ins.loadProvider(); err != nil {
return
}
})
return err
}

// loadProvider loads the service provider.
func (ins *Instance) loadProvider() error {
var srvOpts []server.ServerOption
if ins.insOpts.Provider != nil {
srvOpts = append(srvOpts, server.SetServerProvider(ins.insOpts.Provider))
}
srv, err := ins.NewServer(srvOpts...)
if err != nil {
return err
}
// register services
proLock.RLock()
defer proLock.RUnlock()
for _, definition := range providerServices {
if err = srv.Register(definition.Handler, definition.Info, definition.Opts...); err != nil {
return err
}
}
go func() {
if err = srv.Serve(); err != nil {
logger.Fatalf("Failed to start server, err: %v", err)
}
}()
return err
}

// loadConsumer loads the service consumer.
func (ins *Instance) loadConsumer() error {
cli, err := ins.NewClient()
if err != nil {
return err
}
// refer services
conLock.RLock()
defer conLock.RUnlock()
for intfName, definition := range consumerServices {
conn, err := cli.DialWithInfo(intfName, definition.Info)

Check failure on line 223 in dubbo.go

View workflow job for this annotation

GitHub Actions / lint (1.17)

shadow: declaration of "err" shadows declaration at line 215 (govet)
if err != nil {
return err
}
definition.Info.ConnectionInjectFunc(definition.Svc, conn)
}
return err
}

// SetConsumerServiceWithInfo sets the consumer service with the client information.
func SetConsumerServiceWithInfo(svc common.RPCService, info *client.ClientInfo) {
conLock.Lock()
defer conLock.Unlock()
consumerServices[info.InterfaceName] = &client.ClientDefinition{
Svc: svc,
Info: info,
}
}

// SetProviderServiceWithInfo sets the provider service with the server information.
func SetProviderServiceWithInfo(svc common.RPCService, info *server.ServiceInfo) {
proLock.Lock()
defer proLock.Unlock()
providerServices[info.InterfaceName] = &server.ServiceDefinition{
Handler: svc,
Info: info,
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ require (
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0
golang.org/x/net v0.8.0
golang.org/x/net v0.17.0
golang.org/x/oauth2 v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef
google.golang.org/grpc v1.52.0
Expand Down
Loading

0 comments on commit f91ee63

Please sign in to comment.