From da1e3565b9d4fe39dccff578c7ff2fc952b3d0c4 Mon Sep 17 00:00:00 2001 From: Scout Wang Date: Tue, 30 Jan 2024 14:25:14 +0800 Subject: [PATCH 1/4] feat: filter token sample --- .github/workflows/github-actions.yml | 30 +-- filter/proto/greet.pb.go | 229 ++++++++++++++++++ filter/proto/greet.proto | 33 +++ filter/proto/greet.triple.go | 122 ++++++++++ filter/token/go-client/cmd/main.go | 57 +++++ filter/token/go-server/cmd/main.go | 67 +++++ .../tests/integration/helloworld_test.go | 37 +++ .../token/tests/integration/main_test.go | 54 +++++ start_integrate_test.sh | 1 + 9 files changed, 615 insertions(+), 15 deletions(-) create mode 100644 filter/proto/greet.pb.go create mode 100644 filter/proto/greet.proto create mode 100644 filter/proto/greet.triple.go create mode 100644 filter/token/go-client/cmd/main.go create mode 100644 filter/token/go-server/cmd/main.go create mode 100644 integrate_test/filter/token/tests/integration/helloworld_test.go create mode 100644 integrate_test/filter/token/tests/integration/main_test.go diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 3bf13a483..75e020bc2 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -64,21 +64,21 @@ jobs: - name: Check License Header uses: apache/skywalking-eyes/header@e1a02359b239bd28de3f6d35fdc870250fa513d5 -# - name: Switch Dubbo-go version -# run: | -# # Acquire information of branch -# if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then -# BRANCH=${{github.base_ref}} -# elif [ "$GITHUB_EVENT_NAME" == "push" ]; then -# BRANCH=$GITHUB_REF_NAME -# else -# echo "$GITHUB_EVENT_NAME event is unsupported right now" -# exit 1 -# fi -# echo "EVENT = $GITHUB_EVENT_NAME, BRANCH = $BRANCH" -# # Edit the version -# go mod edit -replace=dubbo.apache.org/dubbo-go/v3=dubbo.apache.org/dubbo-go/v3@$BRANCH -# go mod tidy + - name: Switch Dubbo-go version + run: | + # Acquire information of branch + if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then + BRANCH=${{github.base_ref}} + elif [ "$GITHUB_EVENT_NAME" == "push" ]; then + BRANCH=$GITHUB_REF_NAME + else + echo "$GITHUB_EVENT_NAME event is unsupported right now" + exit 1 + fi + echo "EVENT = $GITHUB_EVENT_NAME, BRANCH = $BRANCH" + # Edit the version + go mod edit -replace=dubbo.apache.org/dubbo-go/v3=dubbo.apache.org/dubbo-go/v3@$BRANCH + go mod tidy - name: Integration Test run: | diff --git a/filter/proto/greet.pb.go b/filter/proto/greet.pb.go new file mode 100644 index 000000000..34071532e --- /dev/null +++ b/filter/proto/greet.pb.go @@ -0,0 +1,229 @@ +// +// 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. + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.31.0 +// protoc v3.20.3 +// source: greet.proto + +package greet + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type GreetRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *GreetRequest) Reset() { + *x = GreetRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_greet_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GreetRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GreetRequest) ProtoMessage() {} + +func (x *GreetRequest) ProtoReflect() protoreflect.Message { + mi := &file_greet_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GreetRequest.ProtoReflect.Descriptor instead. +func (*GreetRequest) Descriptor() ([]byte, []int) { + return file_greet_proto_rawDescGZIP(), []int{0} +} + +func (x *GreetRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type GreetResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Greeting string `protobuf:"bytes,1,opt,name=greeting,proto3" json:"greeting,omitempty"` +} + +func (x *GreetResponse) Reset() { + *x = GreetResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_greet_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GreetResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GreetResponse) ProtoMessage() {} + +func (x *GreetResponse) ProtoReflect() protoreflect.Message { + mi := &file_greet_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GreetResponse.ProtoReflect.Descriptor instead. +func (*GreetResponse) Descriptor() ([]byte, []int) { + return file_greet_proto_rawDescGZIP(), []int{1} +} + +func (x *GreetResponse) GetGreeting() string { + if x != nil { + return x.Greeting + } + return "" +} + +var File_greet_proto protoreflect.FileDescriptor + +var file_greet_proto_rawDesc = []byte{ + 0x0a, 0x0b, 0x67, 0x72, 0x65, 0x65, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x67, + 0x72, 0x65, 0x65, 0x74, 0x22, 0x22, 0x0a, 0x0c, 0x47, 0x72, 0x65, 0x65, 0x74, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x2b, 0x0a, 0x0d, 0x47, 0x72, 0x65, 0x65, + 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x67, 0x72, 0x65, + 0x65, 0x74, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x67, 0x72, 0x65, + 0x65, 0x74, 0x69, 0x6e, 0x67, 0x32, 0x44, 0x0a, 0x0c, 0x47, 0x72, 0x65, 0x65, 0x74, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x05, 0x47, 0x72, 0x65, 0x65, 0x74, 0x12, 0x13, + 0x2e, 0x67, 0x72, 0x65, 0x65, 0x74, 0x2e, 0x47, 0x72, 0x65, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x67, 0x72, 0x65, 0x65, 0x74, 0x2e, 0x47, 0x72, 0x65, 0x65, + 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x37, 0x5a, 0x35, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x61, 0x63, 0x68, 0x65, + 0x2f, 0x64, 0x75, 0x62, 0x62, 0x6f, 0x2d, 0x67, 0x6f, 0x2d, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, + 0x73, 0x2f, 0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x67, + 0x72, 0x65, 0x65, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_greet_proto_rawDescOnce sync.Once + file_greet_proto_rawDescData = file_greet_proto_rawDesc +) + +func file_greet_proto_rawDescGZIP() []byte { + file_greet_proto_rawDescOnce.Do(func() { + file_greet_proto_rawDescData = protoimpl.X.CompressGZIP(file_greet_proto_rawDescData) + }) + return file_greet_proto_rawDescData +} + +var file_greet_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_greet_proto_goTypes = []interface{}{ + (*GreetRequest)(nil), // 0: greet.GreetRequest + (*GreetResponse)(nil), // 1: greet.GreetResponse +} +var file_greet_proto_depIdxs = []int32{ + 0, // 0: greet.GreetService.Greet:input_type -> greet.GreetRequest + 1, // 1: greet.GreetService.Greet:output_type -> greet.GreetResponse + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_greet_proto_init() } +func file_greet_proto_init() { + if File_greet_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_greet_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GreetRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_greet_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GreetResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_greet_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_greet_proto_goTypes, + DependencyIndexes: file_greet_proto_depIdxs, + MessageInfos: file_greet_proto_msgTypes, + }.Build() + File_greet_proto = out.File + file_greet_proto_rawDesc = nil + file_greet_proto_goTypes = nil + file_greet_proto_depIdxs = nil +} diff --git a/filter/proto/greet.proto b/filter/proto/greet.proto new file mode 100644 index 000000000..11663ea8e --- /dev/null +++ b/filter/proto/greet.proto @@ -0,0 +1,33 @@ +/* + * 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. + */ + +syntax = "proto3"; +package greet; + +option go_package = "github.com/apache/dubbo-go-samples/filter/proto;greet"; + +message GreetRequest { + string name = 1; +} + +message GreetResponse { + string greeting = 1; +} + +service GreetService { + rpc Greet(GreetRequest) returns (GreetResponse) {} +} \ No newline at end of file diff --git a/filter/proto/greet.triple.go b/filter/proto/greet.triple.go new file mode 100644 index 000000000..ca199223e --- /dev/null +++ b/filter/proto/greet.triple.go @@ -0,0 +1,122 @@ +// Code generated by protoc-gen-triple. DO NOT EDIT. +// +// Source: greet.proto +package greet + +import ( + "context" +) + +import ( + "dubbo.apache.org/dubbo-go/v3" + "dubbo.apache.org/dubbo-go/v3/client" + "dubbo.apache.org/dubbo-go/v3/common" + "dubbo.apache.org/dubbo-go/v3/common/constant" + "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol" + "dubbo.apache.org/dubbo-go/v3/server" +) + +// This is a compile-time assertion to ensure that this generated file and the Triple package +// are compatible. If you get a compiler error that this constant is not defined, this code was +// generated with a version of Triple newer than the one compiled into your binary. You can fix the +// problem by either regenerating this code with an older version of Triple or updating the Triple +// version compiled into your binary. +const _ = triple_protocol.IsAtLeastVersion0_1_0 + +const ( + // GreetServiceName is the fully-qualified name of the GreetService service. + GreetServiceName = "greet.GreetService" +) + +// These constants are the fully-qualified names of the RPCs defined in this package. They're +// exposed at runtime as procedure and as the final two segments of the HTTP route. +// +// Note that these are different from the fully-qualified method names used by +// google.golang.org/protobuf/reflect/protoreflect. To convert from these constants to +// reflection-formatted method names, remove the leading slash and convert the remaining slash to a +// period. +const ( + // GreetServiceGreetProcedure is the fully-qualified name of the GreetService's Greet RPC. + GreetServiceGreetProcedure = "/greet.GreetService/Greet" +) + +var ( + _ GreetService = (*GreetServiceImpl)(nil) +) + +// GreetService is a client for the greet.GreetService service. +type GreetService interface { + Greet(ctx context.Context, req *GreetRequest, opts ...client.CallOption) (*GreetResponse, error) +} + +// NewGreetService constructs a client for the greet.GreetService service. +func NewGreetService(cli *client.Client, opts ...client.ReferenceOption) (GreetService, error) { + conn, err := cli.DialWithInfo("greet.GreetService", &GreetService_ClientInfo, opts...) + if err != nil { + return nil, err + } + return &GreetServiceImpl{ + conn: conn, + }, nil +} + +func SetConsumerService(srv common.RPCService) { + dubbo.SetConsumerServiceWithInfo(srv, &GreetService_ClientInfo) +} + +// GreetServiceImpl implements GreetService. +type GreetServiceImpl struct { + conn *client.Connection +} + +func (c *GreetServiceImpl) Greet(ctx context.Context, req *GreetRequest, opts ...client.CallOption) (*GreetResponse, error) { + resp := new(GreetResponse) + if err := c.conn.CallUnary(ctx, []interface{}{req}, resp, "Greet", opts...); err != nil { + return nil, err + } + return resp, nil +} + +var GreetService_ClientInfo = client.ClientInfo{ + InterfaceName: "greet.GreetService", + MethodNames: []string{"Greet"}, + ConnectionInjectFunc: func(dubboCliRaw interface{}, conn *client.Connection) { + dubboCli := dubboCliRaw.(*GreetServiceImpl) + dubboCli.conn = conn + }, +} + +// GreetServiceHandler is an implementation of the greet.GreetService service. +type GreetServiceHandler interface { + Greet(context.Context, *GreetRequest) (*GreetResponse, error) +} + +func RegisterGreetServiceHandler(srv *server.Server, hdlr GreetServiceHandler, opts ...server.ServiceOption) error { + return srv.Register(hdlr, &GreetService_ServiceInfo, opts...) +} + +func SetProviderService(srv common.RPCService) { + dubbo.SetProviderServiceWithInfo(srv, &GreetService_ServiceInfo) +} + +var GreetService_ServiceInfo = server.ServiceInfo{ + InterfaceName: "greet.GreetService", + ServiceType: (*GreetServiceHandler)(nil), + Methods: []server.MethodInfo{ + { + Name: "Greet", + Type: constant.CallUnary, + ReqInitFunc: func() interface{} { + return new(GreetRequest) + }, + MethodFunc: func(ctx context.Context, args []interface{}, handler interface{}) (interface{}, error) { + req := args[0].(*GreetRequest) + res, err := handler.(GreetServiceHandler).Greet(ctx, req) + if err != nil { + return nil, err + } + return triple_protocol.NewResponse(res), nil + }, + }, + }, +} diff --git a/filter/token/go-client/cmd/main.go b/filter/token/go-client/cmd/main.go new file mode 100644 index 000000000..616bfc5c0 --- /dev/null +++ b/filter/token/go-client/cmd/main.go @@ -0,0 +1,57 @@ +/* + * 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 main + +import ( + "context" + + "dubbo.apache.org/dubbo-go/v3" + _ "dubbo.apache.org/dubbo-go/v3/imports" + "dubbo.apache.org/dubbo-go/v3/registry" + greet "github.com/apache/dubbo-go-samples/filter/proto" + "github.com/dubbogo/gost/log/logger" +) + +func main() { + ins, err := dubbo.NewInstance( + dubbo.WithName("dubbo_filter_token_client"), + dubbo.WithRegistry( + registry.WithZookeeper(), + registry.WithAddress("127.0.0.1:2181"), + ), + ) + if err != nil { + panic(err) + } + cli, err := ins.NewClient() + if err != nil { + panic(err) + } + + svc, err := greet.NewGreetService(cli) + if err != nil { + panic(err) + } + + resp, err := svc.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"}) + if err != nil { + logger.Error(err) + return + } + logger.Infof("Greet response: %s", resp.Greeting) +} diff --git a/filter/token/go-server/cmd/main.go b/filter/token/go-server/cmd/main.go new file mode 100644 index 000000000..b516ef3af --- /dev/null +++ b/filter/token/go-server/cmd/main.go @@ -0,0 +1,67 @@ +/* + * 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 main + +import ( + "context" + + "dubbo.apache.org/dubbo-go/v3" + _ "dubbo.apache.org/dubbo-go/v3/imports" + "dubbo.apache.org/dubbo-go/v3/protocol" + "dubbo.apache.org/dubbo-go/v3/registry" + "dubbo.apache.org/dubbo-go/v3/server" + greet "github.com/apache/dubbo-go-samples/filter/proto" + "github.com/dubbogo/gost/log/logger" +) + +type GreetTripleServer struct { +} + +func (srv *GreetTripleServer) Greet(ctx context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) { + resp := &greet.GreetResponse{Greeting: req.Name} + return resp, nil +} + +func main() { + ins, err := dubbo.NewInstance( + dubbo.WithName("dubbo_filter_token_server"), + dubbo.WithRegistry( + registry.WithZookeeper(), + registry.WithAddress("127.0.0.1:2181"), + ), + dubbo.WithProtocol( + protocol.WithTriple(), + protocol.WithPort(20000), + ), + ) + srv, err := ins.NewServer() + if err != nil { + panic(err) + } + + if err := greet.RegisterGreetServiceHandler(srv, &GreetTripleServer{}, + server.WithFilter("token"), + server.WithToken("dubbo-go"), + ); err != nil { + panic(err) + } + + if err := srv.Serve(); err != nil { + logger.Error(err) + } +} diff --git a/integrate_test/filter/token/tests/integration/helloworld_test.go b/integrate_test/filter/token/tests/integration/helloworld_test.go new file mode 100644 index 000000000..57df2c8e9 --- /dev/null +++ b/integrate_test/filter/token/tests/integration/helloworld_test.go @@ -0,0 +1,37 @@ +/* + * 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 integration + +import ( + "context" + "testing" + + greet "github.com/apache/dubbo-go-samples/filter/proto" + "github.com/stretchr/testify/assert" +) + +func TestGreet(t *testing.T) { + req := &greet.GreetRequest{ + Name: "Dubbo", + } + + reply, err := greetService.Greet(context.Background(), req) + + assert.Nil(t, err) + assert.Equal(t, "Dubbo", reply.Greeting) +} diff --git a/integrate_test/filter/token/tests/integration/main_test.go b/integrate_test/filter/token/tests/integration/main_test.go new file mode 100644 index 000000000..4ee19e63d --- /dev/null +++ b/integrate_test/filter/token/tests/integration/main_test.go @@ -0,0 +1,54 @@ +/* + * 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 integration + +import ( + "os" + "testing" + + "dubbo.apache.org/dubbo-go/v3" + "dubbo.apache.org/dubbo-go/v3/registry" + greet "github.com/apache/dubbo-go-samples/filter/proto" +) + +var greetService greet.GreetService + +func TestMain(m *testing.M) { + ins, err := dubbo.NewInstance( + dubbo.WithName("dubbo_filter_token_client"), + dubbo.WithRegistry( + registry.WithZookeeper(), + registry.WithAddress("127.0.0.1:2181"), + ), + ) + if err != nil { + panic(err) + } + // configure the params that only client layer cares + cli, err := ins.NewClient() + if err != nil { + panic(err) + } + + greetService, err = greet.NewGreetService(cli) + if err != nil { + panic(err) + } + + os.Exit(m.Run()) +} diff --git a/start_integrate_test.sh b/start_integrate_test.sh index a1153c920..d643919de 100755 --- a/start_integrate_test.sh +++ b/start_integrate_test.sh @@ -42,6 +42,7 @@ array+=("otel/tracing/stdout") array+=("compatibility/direct") # filer +array+=("filter/token") array+=("compatibility/filter/custom") array+=("compatibility/filter/token") From 7c64788d7fbc68fb34928a63507c3916f073f288 Mon Sep 17 00:00:00 2001 From: Scout Wang Date: Tue, 30 Jan 2024 14:29:50 +0800 Subject: [PATCH 2/4] fix CI --- filter/token/go-server/cmd/main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/filter/token/go-server/cmd/main.go b/filter/token/go-server/cmd/main.go index b516ef3af..cae7ae789 100644 --- a/filter/token/go-server/cmd/main.go +++ b/filter/token/go-server/cmd/main.go @@ -49,6 +49,10 @@ func main() { protocol.WithPort(20000), ), ) + if err != nil { + panic(err) + } + srv, err := ins.NewServer() if err != nil { panic(err) From bc8309765b70d682ff1712022561373515703872 Mon Sep 17 00:00:00 2001 From: Scout Wang Date: Fri, 2 Feb 2024 10:15:48 +0800 Subject: [PATCH 3/4] modify dubbo-go version --- go.mod | 2 +- go.sum | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 4acf912d9..9827ce845 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/apache/dubbo-go-samples require ( - dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240111064552-d21e6995a3c7 + dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240202021041-198504bb0029 github.com/SkyAPM/go2sky v1.5.0 github.com/SkyAPM/go2sky-plugins/dubbo-go v0.0.0-20220718123631-cb8f743b16cf github.com/apache/dubbo-go-hessian2 v1.12.2 diff --git a/go.sum b/go.sum index 72bd12716..434d366a7 100644 --- a/go.sum +++ b/go.sum @@ -600,8 +600,8 @@ contrib.go.opencensus.io/exporter/prometheus v0.4.1/go.mod h1:t9wvfitlUjGXG2IXAZ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dubbo.apache.org/dubbo-go/v3 v3.0.2-0.20220508105316-b27ec53b7bab/go.mod h1:Ytn9MtmsFYkpa1bzW/3loUFBgm7eJ3M3+XWRurhbBZc= dubbo.apache.org/dubbo-go/v3 v3.0.2/go.mod h1:bODgByAf72kzG/5YIfZIODXx81pY3gaAdIQ8B4mN/Yk= -dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240111064552-d21e6995a3c7 h1:1b/vXgmVWuXNq236VMrMP/heS1FLLP7LaY1ctEemQA8= -dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240111064552-d21e6995a3c7/go.mod h1:Aq4YRQHYH5rF6NpeYzPfjTdwhVTOBd5BhdXXstl7EZE= +dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240202021041-198504bb0029 h1:+5r/DyxObRS5gUkyyojGBl/QHs8zIkmX45F0hTjciL4= +dubbo.apache.org/dubbo-go/v3 v3.1.1-0.20240202021041-198504bb0029/go.mod h1:Aq4YRQHYH5rF6NpeYzPfjTdwhVTOBd5BhdXXstl7EZE= gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8= git.sr.ht/~sbinet/gg v0.3.1/go.mod h1:KGYtlADtqsqANL9ueOFkWymvzUvLMQllU5Ixo+8v3pc= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -700,7 +700,9 @@ github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7 github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= +github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= +github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -925,6 +927,7 @@ github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptG github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= +github.com/golang/glog v1.1.0 h1:/d3pCKDPWNnvIWe0vVUpNP32qc8U3PDVxySP/y360qE= github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -1062,6 +1065,7 @@ github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4G github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0/go.mod h1:hgWBS7lorOAVIJEQMi4ZsPv9hVvWI6+ch50m39Pf2Ks= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3/go.mod h1:o//XUCC/F+yRGJoPO/VU0GSB0f8Nhgmxx0VIRUvaC0w= github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645/go.mod h1:6iZfnjpejD4L/4DwD7NryNaJyCQdzwWwH2MWhCA90Kw= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= @@ -1608,9 +1612,13 @@ go.opentelemetry.io/otel v1.11.0 h1:kfToEGMDq6TrVrJ9Vht84Y8y9enykSZzDDZglV0kIEk= go.opentelemetry.io/otel v1.11.0/go.mod h1:H2KtuEphyMvlhZ+F7tg9GRhAOe60moNx61Ex+WmiKkk= go.opentelemetry.io/otel/exporters/jaeger v1.10.0 h1:7W3aVVjEYayu/GOqOVF4mbTvnCuxF1wWu3eRxFGQXvw= go.opentelemetry.io/otel/exporters/jaeger v1.10.0/go.mod h1:n9IGyx0fgyXXZ/i0foLHNxtET9CzXHzZeKCucvRBFgA= +go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0 h1:TaB+1rQhddO1sF71MpZOZAuSPW1klK2M8XxfrBMfK7Y= go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0/go.mod h1:78XhIg8Ht9vR4tbLNUhXsiOnE2HOuSeKAiAcoVQEpOY= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.10.0 h1:pDDYmo0QadUPal5fwXoY1pmMpFcdyhXOmL5drCrI3vU= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.10.0/go.mod h1:Krqnjl22jUJ0HgMzw5eveuCvFDXY4nSYb4F8t5gdrag= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.10.0 h1:KtiUEhQmj/Pa874bVYKGNVdq8NPKiacPbaRRtgXi+t4= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.10.0/go.mod h1:OfUCyyIiDvNXHWpcWgbF+MWvqPZiNa3YDEnivcnYsV0= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.10.0 h1:S8DedULB3gp93Rh+9Z+7NTEv+6Id/KYS7LDyipZ9iCE= go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.10.0/go.mod h1:5WV40MLWwvWlGP7Xm8g3pMcg0pKOUY609qxJn8y7LmM= go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.10.0 h1:c9UtMu/qnbLlVwTwt+ABrURrioEruapIslTDYZHJe2w= go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.10.0/go.mod h1:h3Lrh9t3Dnqp3NPwAZx7i37UFX7xrfnO1D+fuClREOA= @@ -1624,6 +1632,7 @@ go.opentelemetry.io/otel/trace v1.11.0 h1:20U/Vj42SX+mASlXLmSGBg6jpI1jQtv682lZtT go.opentelemetry.io/otel/trace v1.11.0/go.mod h1:nyYjis9jy0gytE9LXGU+/m1sHTKbRY0fX0hulNNDP1U= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.15.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= +go.opentelemetry.io/proto/otlp v0.19.0 h1:IVN6GR+mhC4s5yfcTbmzHYODqvWAp3ZedA2SJPI1Nnw= go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI405h3+duxN4U= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= From ba97362f45350da4e20c3f8f32ad5965cb67ffcd Mon Sep 17 00:00:00 2001 From: Scout Wang Date: Fri, 2 Feb 2024 10:48:23 +0800 Subject: [PATCH 4/4] add dubbo-go import --- integrate_test/filter/token/tests/integration/main_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integrate_test/filter/token/tests/integration/main_test.go b/integrate_test/filter/token/tests/integration/main_test.go index 4ee19e63d..a7ba697e3 100644 --- a/integrate_test/filter/token/tests/integration/main_test.go +++ b/integrate_test/filter/token/tests/integration/main_test.go @@ -22,6 +22,7 @@ import ( "testing" "dubbo.apache.org/dubbo-go/v3" + _ "dubbo.apache.org/dubbo-go/v3/imports" "dubbo.apache.org/dubbo-go/v3/registry" greet "github.com/apache/dubbo-go-samples/filter/proto" )