From 26d5105180a631945b778fb504451dd02923e520 Mon Sep 17 00:00:00 2001 From: luyanbo Date: Sat, 19 Nov 2022 23:23:58 +0800 Subject: [PATCH 1/6] add c-server --- mse-go-demo/c-server/.gitignore | 7 + mse-go-demo/c-server/Dockerfile | 28 +++ mse-go-demo/c-server/Makefile | 4 + mse-go-demo/c-server/go.mod | 16 ++ mse-go-demo/c-server/go.sum | 118 ++++++++++ mse-go-demo/c-server/main.go | 44 ++++ mse-go-demo/c-server/proto/c-api.pb.go | 230 ++++++++++++++++++++ mse-go-demo/c-server/proto/c-api.proto | 34 +++ mse-go-demo/c-server/proto/c-api_grpc.pb.go | 105 +++++++++ 9 files changed, 586 insertions(+) create mode 100644 mse-go-demo/c-server/.gitignore create mode 100644 mse-go-demo/c-server/Dockerfile create mode 100644 mse-go-demo/c-server/Makefile create mode 100644 mse-go-demo/c-server/go.mod create mode 100644 mse-go-demo/c-server/go.sum create mode 100644 mse-go-demo/c-server/main.go create mode 100644 mse-go-demo/c-server/proto/c-api.pb.go create mode 100644 mse-go-demo/c-server/proto/c-api.proto create mode 100644 mse-go-demo/c-server/proto/c-api_grpc.pb.go diff --git a/mse-go-demo/c-server/.gitignore b/mse-go-demo/c-server/.gitignore new file mode 100644 index 00000000..3699de00 --- /dev/null +++ b/mse-go-demo/c-server/.gitignore @@ -0,0 +1,7 @@ +grpc-server +main +__debug_bin +c-server + +.vscode/ + diff --git a/mse-go-demo/c-server/Dockerfile b/mse-go-demo/c-server/Dockerfile new file mode 100644 index 00000000..0f90c081 --- /dev/null +++ b/mse-go-demo/c-server/Dockerfile @@ -0,0 +1,28 @@ +FROM golang:1.19-alpine3.16 as build + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories + +RUN apk --update add gcc libc-dev + +ADD . /workspace + +WORKDIR /workspace + +RUN env GOPROXY=https://goproxy.cn,direct \ + go build -buildmode=pie -ldflags "-linkmode external -extldflags -static -w" -o /workspace + +# The RUN line below is an alternative that also results in a static binary +# that can be run FROM scratch but results in a slightly-larger executable +# without ASLR. +# +# RUN CGO_ENABLED=0 go build -a -o arms-pilot + +FROM alpine:3.16 + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories + +COPY --from=build /workspace/c-server /c-server + +EXPOSE 50051 + +CMD ["/c-server"] diff --git a/mse-go-demo/c-server/Makefile b/mse-go-demo/c-server/Makefile new file mode 100644 index 00000000..c3e71172 --- /dev/null +++ b/mse-go-demo/c-server/Makefile @@ -0,0 +1,4 @@ +all: + protoc --go_out=. --go_opt=paths=source_relative \ + --go-grpc_out=. --go-grpc_opt=paths=source_relative \ + proto/*.proto diff --git a/mse-go-demo/c-server/go.mod b/mse-go-demo/c-server/go.mod new file mode 100644 index 00000000..e9b3df80 --- /dev/null +++ b/mse-go-demo/c-server/go.mod @@ -0,0 +1,16 @@ +module github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/c-server + +go 1.19 + +require ( + google.golang.org/grpc v1.40.0 +) + +require ( + github.com/golang/protobuf v1.5.2 // indirect + golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect + golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect + golang.org/x/text v0.3.0 // indirect + google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect + google.golang.org/protobuf v1.27.1 // indirect +) diff --git a/mse-go-demo/c-server/go.sum b/mse-go-demo/c-server/go.sum new file mode 100644 index 00000000..57d19717 --- /dev/null +++ b/mse-go-demo/c-server/go.sum @@ -0,0 +1,118 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q= +google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/mse-go-demo/c-server/main.go b/mse-go-demo/c-server/main.go new file mode 100644 index 00000000..e691f02f --- /dev/null +++ b/mse-go-demo/c-server/main.go @@ -0,0 +1,44 @@ +// Package main implements a server for Greeter service. +package main + +import ( + "context" + "log" + "net" + + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" + + pb "github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/c-server/proto" +) + +const ( + port = ":50051" +) + +// server is used to implement helloworld.GreeterServer. +type server struct { + pb.UnimplementedCServiceServer +} + +func (s *server) CMethod(context.Context, *pb.CRequest) (*pb.CReply, error) { + reply := &pb.CReply{ + Message: "C", + } + return reply, nil +} + +func main() { + lis, err := net.Listen("tcp", port) + if err != nil { + log.Fatalf("failed to listen: %v", err) + } + s := grpc.NewServer() + pb.RegisterCServiceServer(s, &server{}) + log.Printf("server listening at %v", lis.Addr()) + // Register reflection service on gRPC server. + reflection.Register(s) + if err := s.Serve(lis); err != nil { + log.Fatalf("failed to serve: %v", err) + } +} diff --git a/mse-go-demo/c-server/proto/c-api.pb.go b/mse-go-demo/c-server/proto/c-api.pb.go new file mode 100644 index 00000000..6ff572b6 --- /dev/null +++ b/mse-go-demo/c-server/proto/c-api.pb.go @@ -0,0 +1,230 @@ +// Copyright 2015 gRPC authors. +// +// Licensed 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.28.0 +// protoc v3.19.0 +// source: proto/c-api.proto + +package c_api + +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 CRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *CRequest) Reset() { + *x = CRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_c_api_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CRequest) ProtoMessage() {} + +func (x *CRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_c_api_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 CRequest.ProtoReflect.Descriptor instead. +func (*CRequest) Descriptor() ([]byte, []int) { + return file_proto_c_api_proto_rawDescGZIP(), []int{0} +} + +func (x *CRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type CReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *CReply) Reset() { + *x = CReply{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_c_api_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CReply) ProtoMessage() {} + +func (x *CReply) ProtoReflect() protoreflect.Message { + mi := &file_proto_c_api_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 CReply.ProtoReflect.Descriptor instead. +func (*CReply) Descriptor() ([]byte, []int) { + return file_proto_c_api_proto_rawDescGZIP(), []int{1} +} + +func (x *CReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_proto_c_api_proto protoreflect.FileDescriptor + +var file_proto_c_api_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x2d, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x63, 0x5f, 0x61, 0x70, 0x69, 0x22, 0x1e, 0x0a, 0x08, 0x43, 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, 0x22, 0x0a, 0x06, 0x43, 0x52, + 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x37, + 0x0a, 0x08, 0x43, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2b, 0x0a, 0x07, 0x63, 0x4d, + 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x0f, 0x2e, 0x63, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x63, 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x43, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x76, 0x0a, 0x23, 0x63, 0x6f, 0x6d, 0x2e, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x61, 0x6c, 0x69, 0x79, 0x75, 0x6e, 0x2e, 0x6d, 0x73, 0x65, + 0x5f, 0x67, 0x6f, 0x5f, 0x64, 0x65, 0x6d, 0x6f, 0x2e, 0x63, 0x5f, 0x61, 0x70, 0x69, 0x42, 0x09, + 0x43, 0x41, 0x70, 0x69, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x42, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x6c, 0x69, 0x79, 0x75, 0x6e, 0x2f, 0x61, + 0x6c, 0x69, 0x62, 0x61, 0x62, 0x61, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x2d, 0x6d, 0x69, 0x63, 0x72, + 0x6f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x2f, 0x6d, 0x73, + 0x65, 0x2d, 0x67, 0x6f, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x2f, 0x63, 0x2d, 0x61, 0x70, 0x69, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proto_c_api_proto_rawDescOnce sync.Once + file_proto_c_api_proto_rawDescData = file_proto_c_api_proto_rawDesc +) + +func file_proto_c_api_proto_rawDescGZIP() []byte { + file_proto_c_api_proto_rawDescOnce.Do(func() { + file_proto_c_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_c_api_proto_rawDescData) + }) + return file_proto_c_api_proto_rawDescData +} + +var file_proto_c_api_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_proto_c_api_proto_goTypes = []interface{}{ + (*CRequest)(nil), // 0: c_api.CRequest + (*CReply)(nil), // 1: c_api.CReply +} +var file_proto_c_api_proto_depIdxs = []int32{ + 0, // 0: c_api.CService.cMethod:input_type -> c_api.CRequest + 1, // 1: c_api.CService.cMethod:output_type -> c_api.CReply + 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_proto_c_api_proto_init() } +func file_proto_c_api_proto_init() { + if File_proto_c_api_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_c_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_c_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CReply); 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_proto_c_api_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_c_api_proto_goTypes, + DependencyIndexes: file_proto_c_api_proto_depIdxs, + MessageInfos: file_proto_c_api_proto_msgTypes, + }.Build() + File_proto_c_api_proto = out.File + file_proto_c_api_proto_rawDesc = nil + file_proto_c_api_proto_goTypes = nil + file_proto_c_api_proto_depIdxs = nil +} diff --git a/mse-go-demo/c-server/proto/c-api.proto b/mse-go-demo/c-server/proto/c-api.proto new file mode 100644 index 00000000..b4174dbb --- /dev/null +++ b/mse-go-demo/c-server/proto/c-api.proto @@ -0,0 +1,34 @@ +// Copyright 2015 gRPC authors. +// +// Licensed 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"; + +option go_package = "github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/c-api"; +option java_multiple_files = true; +option java_package = "com.github.aliyun.mse_go_demo.c_api"; +option java_outer_classname = "CApiProto"; + +package c_api; + +service CService { + rpc cMethod (CRequest) returns (CReply) {} +} + +message CRequest { + string name = 1; +} + +message CReply { + string message = 1; +} diff --git a/mse-go-demo/c-server/proto/c-api_grpc.pb.go b/mse-go-demo/c-server/proto/c-api_grpc.pb.go new file mode 100644 index 00000000..e9e749ac --- /dev/null +++ b/mse-go-demo/c-server/proto/c-api_grpc.pb.go @@ -0,0 +1,105 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.19.0 +// source: proto/c-api.proto + +package c_api + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// CServiceClient is the client API for CService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type CServiceClient interface { + CMethod(ctx context.Context, in *CRequest, opts ...grpc.CallOption) (*CReply, error) +} + +type cServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewCServiceClient(cc grpc.ClientConnInterface) CServiceClient { + return &cServiceClient{cc} +} + +func (c *cServiceClient) CMethod(ctx context.Context, in *CRequest, opts ...grpc.CallOption) (*CReply, error) { + out := new(CReply) + err := c.cc.Invoke(ctx, "/c_api.CService/cMethod", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// CServiceServer is the server API for CService service. +// All implementations must embed UnimplementedCServiceServer +// for forward compatibility +type CServiceServer interface { + CMethod(context.Context, *CRequest) (*CReply, error) + mustEmbedUnimplementedCServiceServer() +} + +// UnimplementedCServiceServer must be embedded to have forward compatible implementations. +type UnimplementedCServiceServer struct { +} + +func (UnimplementedCServiceServer) CMethod(context.Context, *CRequest) (*CReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method CMethod not implemented") +} +func (UnimplementedCServiceServer) mustEmbedUnimplementedCServiceServer() {} + +// UnsafeCServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to CServiceServer will +// result in compilation errors. +type UnsafeCServiceServer interface { + mustEmbedUnimplementedCServiceServer() +} + +func RegisterCServiceServer(s grpc.ServiceRegistrar, srv CServiceServer) { + s.RegisterService(&CService_ServiceDesc, srv) +} + +func _CService_CMethod_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CServiceServer).CMethod(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/c_api.CService/cMethod", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CServiceServer).CMethod(ctx, req.(*CRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// CService_ServiceDesc is the grpc.ServiceDesc for CService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var CService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "c_api.CService", + HandlerType: (*CServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "cMethod", + Handler: _CService_CMethod_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "proto/c-api.proto", +} From c31730836d22dcf4d603a28a28e49349d6d6d064 Mon Sep 17 00:00:00 2001 From: luyanbo Date: Sat, 19 Nov 2022 23:34:21 +0800 Subject: [PATCH 2/6] add b-server --- mse-go-demo/b-server/.gitignore | 7 + mse-go-demo/b-server/Dockerfile | 28 +++ mse-go-demo/b-server/Makefile | 4 + mse-go-demo/b-server/go.mod | 16 ++ mse-go-demo/b-server/go.sum | 118 +++++++++ mse-go-demo/b-server/main.go | 63 +++++ mse-go-demo/b-server/proto/b_api/b-api.pb.go | 230 ++++++++++++++++++ mse-go-demo/b-server/proto/b_api/b-api.proto | 34 +++ .../b-server/proto/b_api/b-api_grpc.pb.go | 105 ++++++++ mse-go-demo/b-server/proto/c_api/c-api.pb.go | 230 ++++++++++++++++++ mse-go-demo/b-server/proto/c_api/c-api.proto | 34 +++ .../b-server/proto/c_api/c-api_grpc.pb.go | 105 ++++++++ 12 files changed, 974 insertions(+) create mode 100644 mse-go-demo/b-server/.gitignore create mode 100644 mse-go-demo/b-server/Dockerfile create mode 100644 mse-go-demo/b-server/Makefile create mode 100644 mse-go-demo/b-server/go.mod create mode 100644 mse-go-demo/b-server/go.sum create mode 100644 mse-go-demo/b-server/main.go create mode 100644 mse-go-demo/b-server/proto/b_api/b-api.pb.go create mode 100644 mse-go-demo/b-server/proto/b_api/b-api.proto create mode 100644 mse-go-demo/b-server/proto/b_api/b-api_grpc.pb.go create mode 100644 mse-go-demo/b-server/proto/c_api/c-api.pb.go create mode 100644 mse-go-demo/b-server/proto/c_api/c-api.proto create mode 100644 mse-go-demo/b-server/proto/c_api/c-api_grpc.pb.go diff --git a/mse-go-demo/b-server/.gitignore b/mse-go-demo/b-server/.gitignore new file mode 100644 index 00000000..3024d9e3 --- /dev/null +++ b/mse-go-demo/b-server/.gitignore @@ -0,0 +1,7 @@ +grpc-server +main +__debug_bin +b-server + +.vscode/ + diff --git a/mse-go-demo/b-server/Dockerfile b/mse-go-demo/b-server/Dockerfile new file mode 100644 index 00000000..9a02b585 --- /dev/null +++ b/mse-go-demo/b-server/Dockerfile @@ -0,0 +1,28 @@ +FROM golang:1.19-alpine3.16 as build + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories + +RUN apk --update add gcc libc-dev + +ADD . /workspace + +WORKDIR /workspace + +RUN env GOPROXY=https://goproxy.cn,direct \ + go build -buildmode=pie -ldflags "-linkmode external -extldflags -static -w" -o /workspace + +# The RUN line below is an alternative that also results in a static binary +# that can be run FROM scratch but results in a slightly-larger executable +# without ASLR. +# +# RUN CGO_ENABLED=0 go build -a -o arms-pilot + +FROM alpine:3.16 + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories + +COPY --from=build /workspace/b-server /b-server + +EXPOSE 50051 + +CMD ["/b-server"] diff --git a/mse-go-demo/b-server/Makefile b/mse-go-demo/b-server/Makefile new file mode 100644 index 00000000..432c57a0 --- /dev/null +++ b/mse-go-demo/b-server/Makefile @@ -0,0 +1,4 @@ +all: + protoc --go_out=. --go_opt=paths=source_relative \ + --go-grpc_out=. --go-grpc_opt=paths=source_relative \ + proto/**/*.proto \ No newline at end of file diff --git a/mse-go-demo/b-server/go.mod b/mse-go-demo/b-server/go.mod new file mode 100644 index 00000000..871928bf --- /dev/null +++ b/mse-go-demo/b-server/go.mod @@ -0,0 +1,16 @@ +module github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/b-server + +go 1.19 + +require ( + google.golang.org/grpc v1.40.0 +) + +require ( + github.com/golang/protobuf v1.5.2 // indirect + golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect + golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect + golang.org/x/text v0.3.0 // indirect + google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect + google.golang.org/protobuf v1.27.1 // indirect +) diff --git a/mse-go-demo/b-server/go.sum b/mse-go-demo/b-server/go.sum new file mode 100644 index 00000000..57d19717 --- /dev/null +++ b/mse-go-demo/b-server/go.sum @@ -0,0 +1,118 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q= +google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/mse-go-demo/b-server/main.go b/mse-go-demo/b-server/main.go new file mode 100644 index 00000000..8fd66a8e --- /dev/null +++ b/mse-go-demo/b-server/main.go @@ -0,0 +1,63 @@ +// Package main implements a server for Greeter service. +package main + +import ( + "context" + "log" + "net" + + "google.golang.org/grpc" + "google.golang.org/grpc/reflection" + + b_api_pb "github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/b-server/proto/b_api" + c_api_pb "github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/b-server/proto/c_api" +) + +const ( + port = ":50051" + address = "go-c-service:50051" +) + +// server is used to implement helloworld.GreeterServer. +type server struct { + b_api_pb.UnimplementedBServiceServer + + cClient c_api_pb.CServiceClient +} + +func (s *server) BMethod(ctx context.Context, req *b_api_pb.BRequest) (*b_api_pb.BReply, error) { + cReply, err := s.cClient.CMethod(ctx, &c_api_pb.CRequest{}) + if err != nil { + return nil, err + } + reply := &b_api_pb.BReply{ + Message: cReply.GetMessage() + "-> B", + } + return reply, nil +} + +func main() { + conn, err := grpc.Dial( + address, + grpc.WithInsecure(), + grpc.WithBlock(), + ) + if err != nil { + log.Fatalf("did not connect: %v", err) + } + defer conn.Close() + cClient := c_api_pb.NewCServiceClient(conn) + + lis, err := net.Listen("tcp", port) + if err != nil { + log.Fatalf("failed to listen: %v", err) + } + s := grpc.NewServer() + b_api_pb.RegisterBServiceServer(s, &server{cClient: cClient}) + log.Printf("server listening at %v", lis.Addr()) + // Register reflection service on gRPC server. + reflection.Register(s) + if err := s.Serve(lis); err != nil { + log.Fatalf("failed to serve: %v", err) + } +} diff --git a/mse-go-demo/b-server/proto/b_api/b-api.pb.go b/mse-go-demo/b-server/proto/b_api/b-api.pb.go new file mode 100644 index 00000000..982fb719 --- /dev/null +++ b/mse-go-demo/b-server/proto/b_api/b-api.pb.go @@ -0,0 +1,230 @@ +// Copyright 2015 gRPC authors. +// +// Licensed 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.28.0 +// protoc v3.19.0 +// source: proto/b_api/b-api.proto + +package b_api + +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 BRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *BRequest) Reset() { + *x = BRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_b_api_b_api_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BRequest) ProtoMessage() {} + +func (x *BRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_b_api_b_api_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 BRequest.ProtoReflect.Descriptor instead. +func (*BRequest) Descriptor() ([]byte, []int) { + return file_proto_b_api_b_api_proto_rawDescGZIP(), []int{0} +} + +func (x *BRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type BReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *BReply) Reset() { + *x = BReply{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_b_api_b_api_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BReply) ProtoMessage() {} + +func (x *BReply) ProtoReflect() protoreflect.Message { + mi := &file_proto_b_api_b_api_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 BReply.ProtoReflect.Descriptor instead. +func (*BReply) Descriptor() ([]byte, []int) { + return file_proto_b_api_b_api_proto_rawDescGZIP(), []int{1} +} + +func (x *BReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_proto_b_api_b_api_proto protoreflect.FileDescriptor + +var file_proto_b_api_b_api_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x5f, 0x61, 0x70, 0x69, 0x2f, 0x62, 0x2d, + 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x62, 0x5f, 0x61, 0x70, 0x69, + 0x22, 0x1e, 0x0a, 0x08, 0x42, 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, 0x22, 0x0a, 0x06, 0x42, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x32, 0x37, 0x0a, 0x08, 0x42, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x12, 0x2b, 0x0a, 0x07, 0x62, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x0f, 0x2e, 0x62, 0x5f, + 0x61, 0x70, 0x69, 0x2e, 0x42, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x62, + 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x42, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x76, 0x0a, + 0x23, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x61, 0x6c, 0x69, 0x79, + 0x75, 0x6e, 0x2e, 0x6d, 0x73, 0x65, 0x5f, 0x67, 0x6f, 0x5f, 0x64, 0x65, 0x6d, 0x6f, 0x2e, 0x62, + 0x5f, 0x61, 0x70, 0x69, 0x42, 0x09, 0x42, 0x41, 0x70, 0x69, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, + 0x01, 0x5a, 0x42, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x6c, + 0x69, 0x79, 0x75, 0x6e, 0x2f, 0x61, 0x6c, 0x69, 0x62, 0x61, 0x62, 0x61, 0x63, 0x6c, 0x6f, 0x75, + 0x64, 0x2d, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2d, 0x64, + 0x65, 0x6d, 0x6f, 0x2f, 0x6d, 0x73, 0x65, 0x2d, 0x67, 0x6f, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x2f, + 0x62, 0x2d, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proto_b_api_b_api_proto_rawDescOnce sync.Once + file_proto_b_api_b_api_proto_rawDescData = file_proto_b_api_b_api_proto_rawDesc +) + +func file_proto_b_api_b_api_proto_rawDescGZIP() []byte { + file_proto_b_api_b_api_proto_rawDescOnce.Do(func() { + file_proto_b_api_b_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_b_api_b_api_proto_rawDescData) + }) + return file_proto_b_api_b_api_proto_rawDescData +} + +var file_proto_b_api_b_api_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_proto_b_api_b_api_proto_goTypes = []interface{}{ + (*BRequest)(nil), // 0: b_api.BRequest + (*BReply)(nil), // 1: b_api.BReply +} +var file_proto_b_api_b_api_proto_depIdxs = []int32{ + 0, // 0: b_api.BService.bMethod:input_type -> b_api.BRequest + 1, // 1: b_api.BService.bMethod:output_type -> b_api.BReply + 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_proto_b_api_b_api_proto_init() } +func file_proto_b_api_b_api_proto_init() { + if File_proto_b_api_b_api_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_b_api_b_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_b_api_b_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BReply); 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_proto_b_api_b_api_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_b_api_b_api_proto_goTypes, + DependencyIndexes: file_proto_b_api_b_api_proto_depIdxs, + MessageInfos: file_proto_b_api_b_api_proto_msgTypes, + }.Build() + File_proto_b_api_b_api_proto = out.File + file_proto_b_api_b_api_proto_rawDesc = nil + file_proto_b_api_b_api_proto_goTypes = nil + file_proto_b_api_b_api_proto_depIdxs = nil +} diff --git a/mse-go-demo/b-server/proto/b_api/b-api.proto b/mse-go-demo/b-server/proto/b_api/b-api.proto new file mode 100644 index 00000000..56e437ce --- /dev/null +++ b/mse-go-demo/b-server/proto/b_api/b-api.proto @@ -0,0 +1,34 @@ +// Copyright 2015 gRPC authors. +// +// Licensed 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"; + +option go_package = "github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/b-api"; +option java_multiple_files = true; +option java_package = "com.github.aliyun.mse_go_demo.b_api"; +option java_outer_classname = "BApiProto"; + +package b_api; + +service BService { + rpc bMethod (BRequest) returns (BReply) {} +} + +message BRequest { + string name = 1; +} + +message BReply { + string message = 1; +} diff --git a/mse-go-demo/b-server/proto/b_api/b-api_grpc.pb.go b/mse-go-demo/b-server/proto/b_api/b-api_grpc.pb.go new file mode 100644 index 00000000..ae88a93c --- /dev/null +++ b/mse-go-demo/b-server/proto/b_api/b-api_grpc.pb.go @@ -0,0 +1,105 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.19.0 +// source: proto/b_api/b-api.proto + +package b_api + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// BServiceClient is the client API for BService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type BServiceClient interface { + BMethod(ctx context.Context, in *BRequest, opts ...grpc.CallOption) (*BReply, error) +} + +type bServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewBServiceClient(cc grpc.ClientConnInterface) BServiceClient { + return &bServiceClient{cc} +} + +func (c *bServiceClient) BMethod(ctx context.Context, in *BRequest, opts ...grpc.CallOption) (*BReply, error) { + out := new(BReply) + err := c.cc.Invoke(ctx, "/b_api.BService/bMethod", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// BServiceServer is the server API for BService service. +// All implementations must embed UnimplementedBServiceServer +// for forward compatibility +type BServiceServer interface { + BMethod(context.Context, *BRequest) (*BReply, error) + mustEmbedUnimplementedBServiceServer() +} + +// UnimplementedBServiceServer must be embedded to have forward compatible implementations. +type UnimplementedBServiceServer struct { +} + +func (UnimplementedBServiceServer) BMethod(context.Context, *BRequest) (*BReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method BMethod not implemented") +} +func (UnimplementedBServiceServer) mustEmbedUnimplementedBServiceServer() {} + +// UnsafeBServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to BServiceServer will +// result in compilation errors. +type UnsafeBServiceServer interface { + mustEmbedUnimplementedBServiceServer() +} + +func RegisterBServiceServer(s grpc.ServiceRegistrar, srv BServiceServer) { + s.RegisterService(&BService_ServiceDesc, srv) +} + +func _BService_BMethod_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BServiceServer).BMethod(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/b_api.BService/bMethod", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BServiceServer).BMethod(ctx, req.(*BRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// BService_ServiceDesc is the grpc.ServiceDesc for BService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var BService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "b_api.BService", + HandlerType: (*BServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "bMethod", + Handler: _BService_BMethod_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "proto/b_api/b-api.proto", +} diff --git a/mse-go-demo/b-server/proto/c_api/c-api.pb.go b/mse-go-demo/b-server/proto/c_api/c-api.pb.go new file mode 100644 index 00000000..c08ed102 --- /dev/null +++ b/mse-go-demo/b-server/proto/c_api/c-api.pb.go @@ -0,0 +1,230 @@ +// Copyright 2015 gRPC authors. +// +// Licensed 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.28.0 +// protoc v3.19.0 +// source: proto/c_api/c-api.proto + +package c_api + +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 CRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *CRequest) Reset() { + *x = CRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_c_api_c_api_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CRequest) ProtoMessage() {} + +func (x *CRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_c_api_c_api_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 CRequest.ProtoReflect.Descriptor instead. +func (*CRequest) Descriptor() ([]byte, []int) { + return file_proto_c_api_c_api_proto_rawDescGZIP(), []int{0} +} + +func (x *CRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type CReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *CReply) Reset() { + *x = CReply{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_c_api_c_api_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CReply) ProtoMessage() {} + +func (x *CReply) ProtoReflect() protoreflect.Message { + mi := &file_proto_c_api_c_api_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 CReply.ProtoReflect.Descriptor instead. +func (*CReply) Descriptor() ([]byte, []int) { + return file_proto_c_api_c_api_proto_rawDescGZIP(), []int{1} +} + +func (x *CReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_proto_c_api_c_api_proto protoreflect.FileDescriptor + +var file_proto_c_api_c_api_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x5f, 0x61, 0x70, 0x69, 0x2f, 0x63, 0x2d, + 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x63, 0x5f, 0x61, 0x70, 0x69, + 0x22, 0x1e, 0x0a, 0x08, 0x43, 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, 0x22, 0x0a, 0x06, 0x43, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x32, 0x37, 0x0a, 0x08, 0x43, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x12, 0x2b, 0x0a, 0x07, 0x63, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x0f, 0x2e, 0x63, 0x5f, + 0x61, 0x70, 0x69, 0x2e, 0x43, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x63, + 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x76, 0x0a, + 0x23, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x61, 0x6c, 0x69, 0x79, + 0x75, 0x6e, 0x2e, 0x6d, 0x73, 0x65, 0x5f, 0x67, 0x6f, 0x5f, 0x64, 0x65, 0x6d, 0x6f, 0x2e, 0x63, + 0x5f, 0x61, 0x70, 0x69, 0x42, 0x09, 0x43, 0x41, 0x70, 0x69, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, + 0x01, 0x5a, 0x42, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x6c, + 0x69, 0x79, 0x75, 0x6e, 0x2f, 0x61, 0x6c, 0x69, 0x62, 0x61, 0x62, 0x61, 0x63, 0x6c, 0x6f, 0x75, + 0x64, 0x2d, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2d, 0x64, + 0x65, 0x6d, 0x6f, 0x2f, 0x6d, 0x73, 0x65, 0x2d, 0x67, 0x6f, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x2f, + 0x63, 0x2d, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proto_c_api_c_api_proto_rawDescOnce sync.Once + file_proto_c_api_c_api_proto_rawDescData = file_proto_c_api_c_api_proto_rawDesc +) + +func file_proto_c_api_c_api_proto_rawDescGZIP() []byte { + file_proto_c_api_c_api_proto_rawDescOnce.Do(func() { + file_proto_c_api_c_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_c_api_c_api_proto_rawDescData) + }) + return file_proto_c_api_c_api_proto_rawDescData +} + +var file_proto_c_api_c_api_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_proto_c_api_c_api_proto_goTypes = []interface{}{ + (*CRequest)(nil), // 0: c_api.CRequest + (*CReply)(nil), // 1: c_api.CReply +} +var file_proto_c_api_c_api_proto_depIdxs = []int32{ + 0, // 0: c_api.CService.cMethod:input_type -> c_api.CRequest + 1, // 1: c_api.CService.cMethod:output_type -> c_api.CReply + 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_proto_c_api_c_api_proto_init() } +func file_proto_c_api_c_api_proto_init() { + if File_proto_c_api_c_api_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_c_api_c_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_c_api_c_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CReply); 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_proto_c_api_c_api_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_c_api_c_api_proto_goTypes, + DependencyIndexes: file_proto_c_api_c_api_proto_depIdxs, + MessageInfos: file_proto_c_api_c_api_proto_msgTypes, + }.Build() + File_proto_c_api_c_api_proto = out.File + file_proto_c_api_c_api_proto_rawDesc = nil + file_proto_c_api_c_api_proto_goTypes = nil + file_proto_c_api_c_api_proto_depIdxs = nil +} diff --git a/mse-go-demo/b-server/proto/c_api/c-api.proto b/mse-go-demo/b-server/proto/c_api/c-api.proto new file mode 100644 index 00000000..b4174dbb --- /dev/null +++ b/mse-go-demo/b-server/proto/c_api/c-api.proto @@ -0,0 +1,34 @@ +// Copyright 2015 gRPC authors. +// +// Licensed 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"; + +option go_package = "github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/c-api"; +option java_multiple_files = true; +option java_package = "com.github.aliyun.mse_go_demo.c_api"; +option java_outer_classname = "CApiProto"; + +package c_api; + +service CService { + rpc cMethod (CRequest) returns (CReply) {} +} + +message CRequest { + string name = 1; +} + +message CReply { + string message = 1; +} diff --git a/mse-go-demo/b-server/proto/c_api/c-api_grpc.pb.go b/mse-go-demo/b-server/proto/c_api/c-api_grpc.pb.go new file mode 100644 index 00000000..eca5b660 --- /dev/null +++ b/mse-go-demo/b-server/proto/c_api/c-api_grpc.pb.go @@ -0,0 +1,105 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.19.0 +// source: proto/c_api/c-api.proto + +package c_api + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// CServiceClient is the client API for CService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type CServiceClient interface { + CMethod(ctx context.Context, in *CRequest, opts ...grpc.CallOption) (*CReply, error) +} + +type cServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewCServiceClient(cc grpc.ClientConnInterface) CServiceClient { + return &cServiceClient{cc} +} + +func (c *cServiceClient) CMethod(ctx context.Context, in *CRequest, opts ...grpc.CallOption) (*CReply, error) { + out := new(CReply) + err := c.cc.Invoke(ctx, "/c_api.CService/cMethod", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// CServiceServer is the server API for CService service. +// All implementations must embed UnimplementedCServiceServer +// for forward compatibility +type CServiceServer interface { + CMethod(context.Context, *CRequest) (*CReply, error) + mustEmbedUnimplementedCServiceServer() +} + +// UnimplementedCServiceServer must be embedded to have forward compatible implementations. +type UnimplementedCServiceServer struct { +} + +func (UnimplementedCServiceServer) CMethod(context.Context, *CRequest) (*CReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method CMethod not implemented") +} +func (UnimplementedCServiceServer) mustEmbedUnimplementedCServiceServer() {} + +// UnsafeCServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to CServiceServer will +// result in compilation errors. +type UnsafeCServiceServer interface { + mustEmbedUnimplementedCServiceServer() +} + +func RegisterCServiceServer(s grpc.ServiceRegistrar, srv CServiceServer) { + s.RegisterService(&CService_ServiceDesc, srv) +} + +func _CService_CMethod_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CServiceServer).CMethod(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/c_api.CService/cMethod", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CServiceServer).CMethod(ctx, req.(*CRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// CService_ServiceDesc is the grpc.ServiceDesc for CService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var CService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "c_api.CService", + HandlerType: (*CServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "cMethod", + Handler: _CService_CMethod_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "proto/c_api/c-api.proto", +} From 779f9dcb91a0a7d362df5c7627d0c1ba8d66fddf Mon Sep 17 00:00:00 2001 From: luyanbo Date: Sat, 19 Nov 2022 23:57:47 +0800 Subject: [PATCH 3/6] add a-server --- mse-go-demo/a-server/.gitignore | 7 + mse-go-demo/a-server/Dockerfile | 29 +++ mse-go-demo/a-server/Makefile | 15 ++ mse-go-demo/a-server/go.mod | 16 ++ mse-go-demo/a-server/go.sum | 118 +++++++++ mse-go-demo/a-server/main.go | 47 ++++ mse-go-demo/a-server/proto/b_api/b-api.pb.go | 230 ++++++++++++++++++ mse-go-demo/a-server/proto/b_api/b-api.proto | 34 +++ .../a-server/proto/b_api/b-api_grpc.pb.go | 105 ++++++++ 9 files changed, 601 insertions(+) create mode 100644 mse-go-demo/a-server/.gitignore create mode 100644 mse-go-demo/a-server/Dockerfile create mode 100644 mse-go-demo/a-server/Makefile create mode 100644 mse-go-demo/a-server/go.mod create mode 100644 mse-go-demo/a-server/go.sum create mode 100644 mse-go-demo/a-server/main.go create mode 100644 mse-go-demo/a-server/proto/b_api/b-api.pb.go create mode 100644 mse-go-demo/a-server/proto/b_api/b-api.proto create mode 100644 mse-go-demo/a-server/proto/b_api/b-api_grpc.pb.go diff --git a/mse-go-demo/a-server/.gitignore b/mse-go-demo/a-server/.gitignore new file mode 100644 index 00000000..a773474a --- /dev/null +++ b/mse-go-demo/a-server/.gitignore @@ -0,0 +1,7 @@ +grpc-server +main +__debug_bin +a-server + +.vscode/ + diff --git a/mse-go-demo/a-server/Dockerfile b/mse-go-demo/a-server/Dockerfile new file mode 100644 index 00000000..7081edb7 --- /dev/null +++ b/mse-go-demo/a-server/Dockerfile @@ -0,0 +1,29 @@ +FROM golang:1.19-alpine3.16 as build + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories + +RUN apk --update add gcc libc-dev + +ADD . /workspace + +WORKDIR /workspace + +RUN --mount=type=cache,target=/go \ + env GOPROXY=https://goproxy.cn,direct \ + go build -buildmode=pie -ldflags "-linkmode external -extldflags -static -w" -o /workspace + +# The RUN line below is an alternative that also results in a static binary +# that can be run FROM scratch but results in a slightly-larger executable +# without ASLR. +# +# RUN CGO_ENABLED=0 go build -a -o arms-pilot + +FROM alpine:3.16 + +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories + +COPY --from=build /workspace/a-server /a-server + +EXPOSE 50051 + +CMD ["/a-server"] diff --git a/mse-go-demo/a-server/Makefile b/mse-go-demo/a-server/Makefile new file mode 100644 index 00000000..0e469a7f --- /dev/null +++ b/mse-go-demo/a-server/Makefile @@ -0,0 +1,15 @@ +REGISTRY ?= +IMAGE_NAME ?= a-server +IMAGE_TAG ?= 0.1.0 +IMG ?= ${REGISTRY}${IMAGE_NAME}:${IMAGE_TAG} + +docker-build: + docker build -t ${IMG} . --platform=linux/amd64 + +docker-push: docker-build + docker push $(IMG) + +all: + protoc --go_out=. --go_opt=paths=source_relative \ + --go-grpc_out=. --go-grpc_opt=paths=source_relative \ + proto/**/*.proto \ No newline at end of file diff --git a/mse-go-demo/a-server/go.mod b/mse-go-demo/a-server/go.mod new file mode 100644 index 00000000..1070ac89 --- /dev/null +++ b/mse-go-demo/a-server/go.mod @@ -0,0 +1,16 @@ +module github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/a-server + +go 1.19 + +require ( + google.golang.org/grpc v1.40.0 +) + +require ( + github.com/golang/protobuf v1.5.2 // indirect + golang.org/x/net v0.0.0-20200822124328-c89045814202 // indirect + golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect + golang.org/x/text v0.3.0 // indirect + google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect + google.golang.org/protobuf v1.27.1 // indirect +) diff --git a/mse-go-demo/a-server/go.sum b/mse-go-demo/a-server/go.sum new file mode 100644 index 00000000..57d19717 --- /dev/null +++ b/mse-go-demo/a-server/go.sum @@ -0,0 +1,118 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.40.0 h1:AGJ0Ih4mHjSeibYkFGh1dD9KJ/eOtZ93I6hoHhukQ5Q= +google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/mse-go-demo/a-server/main.go b/mse-go-demo/a-server/main.go new file mode 100644 index 00000000..ecc55bce --- /dev/null +++ b/mse-go-demo/a-server/main.go @@ -0,0 +1,47 @@ +// Package main implements a server for Greeter service. +package main + +import ( + "context" + "log" + "net/http" + + "google.golang.org/grpc" + + b_api_pb "github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/a-server/proto/b_api" +) + +const ( + port = ":8080" + + address = "go-b-service:50051" +) + +var bClient b_api_pb.BServiceClient + +func handler(w http.ResponseWriter, r *http.Request) { + ctx := context.Background() + bReply, err := bClient.BMethod(ctx, &b_api_pb.BRequest{}) + if err != nil { + w.WriteHeader(500) + return + } + content := "A->" + bReply.GetMessage() + w.Write([]byte(content)) +} + +func main() { + conn, err := grpc.Dial( + address, + grpc.WithInsecure(), + grpc.WithBlock(), + ) + if err != nil { + log.Fatalf("did not connect: %v", err) + } + defer conn.Close() + bClient = b_api_pb.NewBServiceClient(conn) + + http.HandleFunc("/", handler) + log.Fatal(http.ListenAndServe(port, nil)) +} diff --git a/mse-go-demo/a-server/proto/b_api/b-api.pb.go b/mse-go-demo/a-server/proto/b_api/b-api.pb.go new file mode 100644 index 00000000..982fb719 --- /dev/null +++ b/mse-go-demo/a-server/proto/b_api/b-api.pb.go @@ -0,0 +1,230 @@ +// Copyright 2015 gRPC authors. +// +// Licensed 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.28.0 +// protoc v3.19.0 +// source: proto/b_api/b-api.proto + +package b_api + +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 BRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` +} + +func (x *BRequest) Reset() { + *x = BRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_b_api_b_api_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BRequest) ProtoMessage() {} + +func (x *BRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_b_api_b_api_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 BRequest.ProtoReflect.Descriptor instead. +func (*BRequest) Descriptor() ([]byte, []int) { + return file_proto_b_api_b_api_proto_rawDescGZIP(), []int{0} +} + +func (x *BRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +type BReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *BReply) Reset() { + *x = BReply{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_b_api_b_api_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BReply) ProtoMessage() {} + +func (x *BReply) ProtoReflect() protoreflect.Message { + mi := &file_proto_b_api_b_api_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 BReply.ProtoReflect.Descriptor instead. +func (*BReply) Descriptor() ([]byte, []int) { + return file_proto_b_api_b_api_proto_rawDescGZIP(), []int{1} +} + +func (x *BReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_proto_b_api_b_api_proto protoreflect.FileDescriptor + +var file_proto_b_api_b_api_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x62, 0x5f, 0x61, 0x70, 0x69, 0x2f, 0x62, 0x2d, + 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x62, 0x5f, 0x61, 0x70, 0x69, + 0x22, 0x1e, 0x0a, 0x08, 0x42, 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, 0x22, 0x0a, 0x06, 0x42, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x32, 0x37, 0x0a, 0x08, 0x42, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, + 0x12, 0x2b, 0x0a, 0x07, 0x62, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x0f, 0x2e, 0x62, 0x5f, + 0x61, 0x70, 0x69, 0x2e, 0x42, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0d, 0x2e, 0x62, + 0x5f, 0x61, 0x70, 0x69, 0x2e, 0x42, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x76, 0x0a, + 0x23, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x61, 0x6c, 0x69, 0x79, + 0x75, 0x6e, 0x2e, 0x6d, 0x73, 0x65, 0x5f, 0x67, 0x6f, 0x5f, 0x64, 0x65, 0x6d, 0x6f, 0x2e, 0x62, + 0x5f, 0x61, 0x70, 0x69, 0x42, 0x09, 0x42, 0x41, 0x70, 0x69, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, + 0x01, 0x5a, 0x42, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x6c, + 0x69, 0x79, 0x75, 0x6e, 0x2f, 0x61, 0x6c, 0x69, 0x62, 0x61, 0x62, 0x61, 0x63, 0x6c, 0x6f, 0x75, + 0x64, 0x2d, 0x6d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2d, 0x64, + 0x65, 0x6d, 0x6f, 0x2f, 0x6d, 0x73, 0x65, 0x2d, 0x67, 0x6f, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x2f, + 0x62, 0x2d, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proto_b_api_b_api_proto_rawDescOnce sync.Once + file_proto_b_api_b_api_proto_rawDescData = file_proto_b_api_b_api_proto_rawDesc +) + +func file_proto_b_api_b_api_proto_rawDescGZIP() []byte { + file_proto_b_api_b_api_proto_rawDescOnce.Do(func() { + file_proto_b_api_b_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_b_api_b_api_proto_rawDescData) + }) + return file_proto_b_api_b_api_proto_rawDescData +} + +var file_proto_b_api_b_api_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_proto_b_api_b_api_proto_goTypes = []interface{}{ + (*BRequest)(nil), // 0: b_api.BRequest + (*BReply)(nil), // 1: b_api.BReply +} +var file_proto_b_api_b_api_proto_depIdxs = []int32{ + 0, // 0: b_api.BService.bMethod:input_type -> b_api.BRequest + 1, // 1: b_api.BService.bMethod:output_type -> b_api.BReply + 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_proto_b_api_b_api_proto_init() } +func file_proto_b_api_b_api_proto_init() { + if File_proto_b_api_b_api_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_b_api_b_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_b_api_b_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BReply); 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_proto_b_api_b_api_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_b_api_b_api_proto_goTypes, + DependencyIndexes: file_proto_b_api_b_api_proto_depIdxs, + MessageInfos: file_proto_b_api_b_api_proto_msgTypes, + }.Build() + File_proto_b_api_b_api_proto = out.File + file_proto_b_api_b_api_proto_rawDesc = nil + file_proto_b_api_b_api_proto_goTypes = nil + file_proto_b_api_b_api_proto_depIdxs = nil +} diff --git a/mse-go-demo/a-server/proto/b_api/b-api.proto b/mse-go-demo/a-server/proto/b_api/b-api.proto new file mode 100644 index 00000000..56e437ce --- /dev/null +++ b/mse-go-demo/a-server/proto/b_api/b-api.proto @@ -0,0 +1,34 @@ +// Copyright 2015 gRPC authors. +// +// Licensed 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"; + +option go_package = "github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/b-api"; +option java_multiple_files = true; +option java_package = "com.github.aliyun.mse_go_demo.b_api"; +option java_outer_classname = "BApiProto"; + +package b_api; + +service BService { + rpc bMethod (BRequest) returns (BReply) {} +} + +message BRequest { + string name = 1; +} + +message BReply { + string message = 1; +} diff --git a/mse-go-demo/a-server/proto/b_api/b-api_grpc.pb.go b/mse-go-demo/a-server/proto/b_api/b-api_grpc.pb.go new file mode 100644 index 00000000..ae88a93c --- /dev/null +++ b/mse-go-demo/a-server/proto/b_api/b-api_grpc.pb.go @@ -0,0 +1,105 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.19.0 +// source: proto/b_api/b-api.proto + +package b_api + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// BServiceClient is the client API for BService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type BServiceClient interface { + BMethod(ctx context.Context, in *BRequest, opts ...grpc.CallOption) (*BReply, error) +} + +type bServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewBServiceClient(cc grpc.ClientConnInterface) BServiceClient { + return &bServiceClient{cc} +} + +func (c *bServiceClient) BMethod(ctx context.Context, in *BRequest, opts ...grpc.CallOption) (*BReply, error) { + out := new(BReply) + err := c.cc.Invoke(ctx, "/b_api.BService/bMethod", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// BServiceServer is the server API for BService service. +// All implementations must embed UnimplementedBServiceServer +// for forward compatibility +type BServiceServer interface { + BMethod(context.Context, *BRequest) (*BReply, error) + mustEmbedUnimplementedBServiceServer() +} + +// UnimplementedBServiceServer must be embedded to have forward compatible implementations. +type UnimplementedBServiceServer struct { +} + +func (UnimplementedBServiceServer) BMethod(context.Context, *BRequest) (*BReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method BMethod not implemented") +} +func (UnimplementedBServiceServer) mustEmbedUnimplementedBServiceServer() {} + +// UnsafeBServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to BServiceServer will +// result in compilation errors. +type UnsafeBServiceServer interface { + mustEmbedUnimplementedBServiceServer() +} + +func RegisterBServiceServer(s grpc.ServiceRegistrar, srv BServiceServer) { + s.RegisterService(&BService_ServiceDesc, srv) +} + +func _BService_BMethod_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(BServiceServer).BMethod(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/b_api.BService/bMethod", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(BServiceServer).BMethod(ctx, req.(*BRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// BService_ServiceDesc is the grpc.ServiceDesc for BService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var BService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "b_api.BService", + HandlerType: (*BServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "bMethod", + Handler: _BService_BMethod_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "proto/b_api/b-api.proto", +} From 50a849c732b01138f1d6318956b7a39b7e6485a7 Mon Sep 17 00:00:00 2001 From: luyanbo Date: Sat, 19 Nov 2022 23:58:01 +0800 Subject: [PATCH 4/6] update Makefile --- mse-go-demo/b-server/Dockerfile | 3 ++- mse-go-demo/b-server/Makefile | 11 +++++++++++ mse-go-demo/b-server/main.go | 2 +- mse-go-demo/c-server/Dockerfile | 3 ++- mse-go-demo/c-server/Makefile | 11 +++++++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/mse-go-demo/b-server/Dockerfile b/mse-go-demo/b-server/Dockerfile index 9a02b585..aab3cb60 100644 --- a/mse-go-demo/b-server/Dockerfile +++ b/mse-go-demo/b-server/Dockerfile @@ -8,7 +8,8 @@ ADD . /workspace WORKDIR /workspace -RUN env GOPROXY=https://goproxy.cn,direct \ +RUN --mount=type=cache,target=/go \ + env GOPROXY=https://goproxy.cn,direct \ go build -buildmode=pie -ldflags "-linkmode external -extldflags -static -w" -o /workspace # The RUN line below is an alternative that also results in a static binary diff --git a/mse-go-demo/b-server/Makefile b/mse-go-demo/b-server/Makefile index 432c57a0..64f1287d 100644 --- a/mse-go-demo/b-server/Makefile +++ b/mse-go-demo/b-server/Makefile @@ -1,3 +1,14 @@ +REGISTRY ?= +IMAGE_NAME ?= b-server +IMAGE_TAG ?= 0.1.0 +IMG ?= ${REGISTRY}${IMAGE_NAME}:${IMAGE_TAG} + +docker-build: + docker build -t ${IMG} . --platform=linux/amd64 + +docker-push: docker-build + docker push $(IMG) + all: protoc --go_out=. --go_opt=paths=source_relative \ --go-grpc_out=. --go-grpc_opt=paths=source_relative \ diff --git a/mse-go-demo/b-server/main.go b/mse-go-demo/b-server/main.go index 8fd66a8e..8a03f944 100644 --- a/mse-go-demo/b-server/main.go +++ b/mse-go-demo/b-server/main.go @@ -31,7 +31,7 @@ func (s *server) BMethod(ctx context.Context, req *b_api_pb.BRequest) (*b_api_pb return nil, err } reply := &b_api_pb.BReply{ - Message: cReply.GetMessage() + "-> B", + Message: "B->" + cReply.GetMessage(), } return reply, nil } diff --git a/mse-go-demo/c-server/Dockerfile b/mse-go-demo/c-server/Dockerfile index 0f90c081..e90dc915 100644 --- a/mse-go-demo/c-server/Dockerfile +++ b/mse-go-demo/c-server/Dockerfile @@ -8,7 +8,8 @@ ADD . /workspace WORKDIR /workspace -RUN env GOPROXY=https://goproxy.cn,direct \ +RUN --mount=type=cache,target=/go \ + env GOPROXY=https://goproxy.cn,direct \ go build -buildmode=pie -ldflags "-linkmode external -extldflags -static -w" -o /workspace # The RUN line below is an alternative that also results in a static binary diff --git a/mse-go-demo/c-server/Makefile b/mse-go-demo/c-server/Makefile index c3e71172..2a7cd613 100644 --- a/mse-go-demo/c-server/Makefile +++ b/mse-go-demo/c-server/Makefile @@ -1,3 +1,14 @@ +REGISTRY ?= +IMAGE_NAME ?= c-server +IMAGE_TAG ?= 0.1.0 +IMG ?= ${REGISTRY}${IMAGE_NAME}:${IMAGE_TAG} + +docker-build: + docker build -t ${IMG} . --platform=linux/amd64 + +docker-push: docker-build + docker push $(IMG) + all: protoc --go_out=. --go_opt=paths=source_relative \ --go-grpc_out=. --go-grpc_opt=paths=source_relative \ From 2bce1fc14126c2130ce20e46f1eb192070920e08 Mon Sep 17 00:00:00 2001 From: luyanbo Date: Sun, 20 Nov 2022 01:42:13 +0800 Subject: [PATCH 5/6] add parseTag --- mse-go-demo/a-server/main.go | 78 +++++++++++++++++++++++++++++------- mse-go-demo/b-server/main.go | 67 ++++++++++++++++++++++++------- mse-go-demo/c-server/main.go | 40 +++++++++++++++++- 3 files changed, 154 insertions(+), 31 deletions(-) diff --git a/mse-go-demo/a-server/main.go b/mse-go-demo/a-server/main.go index ecc55bce..9fa9e6ab 100644 --- a/mse-go-demo/a-server/main.go +++ b/mse-go-demo/a-server/main.go @@ -3,12 +3,16 @@ package main import ( "context" + "fmt" + "io/ioutil" "log" "net/http" - - "google.golang.org/grpc" + "os" + "regexp" + "time" b_api_pb "github.com/aliyun/alibabacloud-microservice-demo/mse-go-demo/a-server/proto/b_api" + "google.golang.org/grpc" ) const ( @@ -17,21 +21,14 @@ const ( address = "go-b-service:50051" ) -var bClient b_api_pb.BServiceClient - func handler(w http.ResponseWriter, r *http.Request) { + fmt.Printf("requesting: %v\n", r.URL) ctx := context.Background() - bReply, err := bClient.BMethod(ctx, &b_api_pb.BRequest{}) - if err != nil { - w.WriteHeader(500) - return - } - content := "A->" + bReply.GetMessage() - w.Write([]byte(content)) -} + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() -func main() { - conn, err := grpc.Dial( + conn, err := grpc.DialContext( + ctx, address, grpc.WithInsecure(), grpc.WithBlock(), @@ -40,8 +37,59 @@ func main() { log.Fatalf("did not connect: %v", err) } defer conn.Close() - bClient = b_api_pb.NewBServiceClient(conn) + bClient := b_api_pb.NewBServiceClient(conn) + bReply, err := bClient.BMethod(ctx, &b_api_pb.BRequest{}) + if err != nil { + fmt.Printf("call b-service failed! %v\n", err) + log.Printf("call b-service failed! %v", err) + w.WriteHeader(500) + fmt.Fprint(w, err.Error()) + return + } + content := generateMessage("A") + "->" + bReply.GetMessage() + fmt.Fprintln(w, content) +} + +func main() { + fmt.Println("starting") http.HandleFunc("/", handler) + + fmt.Println("listening") log.Fatal(http.ListenAndServe(port, nil)) } + +func generateMessage(message string) string { + tag := parseTag() + if tag != "" { + message += "-" + tag + } + hostname, err := os.Hostname() + if err == nil { + message += "[" + hostname + "]" + } + return message +} + +func parseTag() string { + var re = regexp.MustCompile(`(?m)alicloud\.service\.tag="(?P.*)"`) + bs, err := ioutil.ReadFile("/etc/podinfo/labels") + if err != nil { + return "" + } + content := string(bs) + result := re.FindStringSubmatch(content) + + groupNames := re.SubexpNames() + index := 0 + for i, name := range groupNames { + if name == "tag" { + index = i + break + } + } + if len(result) <= index { + return "" + } + return result[index] +} diff --git a/mse-go-demo/b-server/main.go b/mse-go-demo/b-server/main.go index 8a03f944..bb2cdcb0 100644 --- a/mse-go-demo/b-server/main.go +++ b/mse-go-demo/b-server/main.go @@ -3,8 +3,11 @@ package main import ( "context" + "io/ioutil" "log" "net" + "os" + "regexp" "google.golang.org/grpc" "google.golang.org/grpc/reflection" @@ -21,23 +24,11 @@ const ( // server is used to implement helloworld.GreeterServer. type server struct { b_api_pb.UnimplementedBServiceServer - - cClient c_api_pb.CServiceClient } func (s *server) BMethod(ctx context.Context, req *b_api_pb.BRequest) (*b_api_pb.BReply, error) { - cReply, err := s.cClient.CMethod(ctx, &c_api_pb.CRequest{}) - if err != nil { - return nil, err - } - reply := &b_api_pb.BReply{ - Message: "B->" + cReply.GetMessage(), - } - return reply, nil -} - -func main() { - conn, err := grpc.Dial( + conn, err := grpc.DialContext( + ctx, address, grpc.WithInsecure(), grpc.WithBlock(), @@ -48,12 +39,23 @@ func main() { defer conn.Close() cClient := c_api_pb.NewCServiceClient(conn) + cReply, err := cClient.CMethod(ctx, &c_api_pb.CRequest{}) + if err != nil { + return nil, err + } + reply := &b_api_pb.BReply{ + Message: generateMessage("B") + "->" + cReply.GetMessage(), + } + return reply, nil +} + +func main() { lis, err := net.Listen("tcp", port) if err != nil { log.Fatalf("failed to listen: %v", err) } s := grpc.NewServer() - b_api_pb.RegisterBServiceServer(s, &server{cClient: cClient}) + b_api_pb.RegisterBServiceServer(s, &server{}) log.Printf("server listening at %v", lis.Addr()) // Register reflection service on gRPC server. reflection.Register(s) @@ -61,3 +63,38 @@ func main() { log.Fatalf("failed to serve: %v", err) } } + +func generateMessage(message string) string { + tag := parseTag() + if tag != "" { + message += "-" + tag + } + hostname, err := os.Hostname() + if err == nil { + message += "[" + hostname + "]" + } + return message +} + +func parseTag() string { + var re = regexp.MustCompile(`(?m)alicloud\.service\.tag="(?P.*)"`) + bs, err := ioutil.ReadFile("/etc/podinfo/labels") + if err != nil { + return "" + } + content := string(bs) + result := re.FindStringSubmatch(content) + + groupNames := re.SubexpNames() + index := 0 + for i, name := range groupNames { + if name == "tag" { + index = i + break + } + } + if len(result) <= index { + return "" + } + return result[index] +} diff --git a/mse-go-demo/c-server/main.go b/mse-go-demo/c-server/main.go index e691f02f..d25176f7 100644 --- a/mse-go-demo/c-server/main.go +++ b/mse-go-demo/c-server/main.go @@ -3,8 +3,11 @@ package main import ( "context" + "io/ioutil" "log" "net" + "os" + "regexp" "google.golang.org/grpc" "google.golang.org/grpc/reflection" @@ -23,7 +26,7 @@ type server struct { func (s *server) CMethod(context.Context, *pb.CRequest) (*pb.CReply, error) { reply := &pb.CReply{ - Message: "C", + Message: generateMessage("C"), } return reply, nil } @@ -42,3 +45,38 @@ func main() { log.Fatalf("failed to serve: %v", err) } } + +func generateMessage(message string) string { + tag := parseTag() + if tag != "" { + message += "-" + tag + } + hostname, err := os.Hostname() + if err == nil { + message += "[" + hostname + "]" + } + return message +} + +func parseTag() string { + var re = regexp.MustCompile(`(?m)alicloud\.service\.tag="(?P.*)"`) + bs, err := ioutil.ReadFile("/etc/podinfo/labels") + if err != nil { + return "" + } + content := string(bs) + result := re.FindStringSubmatch(content) + + groupNames := re.SubexpNames() + index := 0 + for i, name := range groupNames { + if name == "tag" { + index = i + break + } + } + if len(result) <= index { + return "" + } + return result[index] +} From 3c367a1edfe1071e3e21098aac48ab8ab599a07e Mon Sep 17 00:00:00 2001 From: luyanbo Date: Sun, 20 Nov 2022 02:00:52 +0800 Subject: [PATCH 6/6] add mse-go-demo helm --- mse-go-demo/a-server/Makefile | 2 +- mse-go-demo/b-server/Makefile | 2 +- mse-go-demo/c-server/Makefile | 2 +- mse-go-demo/helm/mse-go-demo/.gitignore | 2 + mse-go-demo/helm/mse-go-demo/Chart.yaml | 8 ++++ mse-go-demo/helm/mse-go-demo/README.md | 16 +++++++ .../helm/mse-go-demo/templates/a-server.yaml | 41 ++++++++++++++++++ .../helm/mse-go-demo/templates/a-service.yaml | 17 ++++++++ .../helm/mse-go-demo/templates/b-server.yaml | 41 ++++++++++++++++++ .../helm/mse-go-demo/templates/b-service.yaml | 14 +++++++ .../mse-go-demo/templates/c-server-gray.yaml | 42 +++++++++++++++++++ .../helm/mse-go-demo/templates/c-server.yaml | 41 ++++++++++++++++++ .../helm/mse-go-demo/templates/c-service.yaml | 14 +++++++ mse-go-demo/helm/mse-go-demo/values.yaml | 5 +++ 14 files changed, 244 insertions(+), 3 deletions(-) create mode 100644 mse-go-demo/helm/mse-go-demo/.gitignore create mode 100644 mse-go-demo/helm/mse-go-demo/Chart.yaml create mode 100644 mse-go-demo/helm/mse-go-demo/README.md create mode 100644 mse-go-demo/helm/mse-go-demo/templates/a-server.yaml create mode 100644 mse-go-demo/helm/mse-go-demo/templates/a-service.yaml create mode 100644 mse-go-demo/helm/mse-go-demo/templates/b-server.yaml create mode 100644 mse-go-demo/helm/mse-go-demo/templates/b-service.yaml create mode 100644 mse-go-demo/helm/mse-go-demo/templates/c-server-gray.yaml create mode 100644 mse-go-demo/helm/mse-go-demo/templates/c-server.yaml create mode 100644 mse-go-demo/helm/mse-go-demo/templates/c-service.yaml create mode 100644 mse-go-demo/helm/mse-go-demo/values.yaml diff --git a/mse-go-demo/a-server/Makefile b/mse-go-demo/a-server/Makefile index 0e469a7f..7a3f8796 100644 --- a/mse-go-demo/a-server/Makefile +++ b/mse-go-demo/a-server/Makefile @@ -1,6 +1,6 @@ REGISTRY ?= IMAGE_NAME ?= a-server -IMAGE_TAG ?= 0.1.0 +IMAGE_TAG ?= 1.0.0 IMG ?= ${REGISTRY}${IMAGE_NAME}:${IMAGE_TAG} docker-build: diff --git a/mse-go-demo/b-server/Makefile b/mse-go-demo/b-server/Makefile index 64f1287d..26c06738 100644 --- a/mse-go-demo/b-server/Makefile +++ b/mse-go-demo/b-server/Makefile @@ -1,6 +1,6 @@ REGISTRY ?= IMAGE_NAME ?= b-server -IMAGE_TAG ?= 0.1.0 +IMAGE_TAG ?= 1.0.0 IMG ?= ${REGISTRY}${IMAGE_NAME}:${IMAGE_TAG} docker-build: diff --git a/mse-go-demo/c-server/Makefile b/mse-go-demo/c-server/Makefile index 2a7cd613..f0344e2b 100644 --- a/mse-go-demo/c-server/Makefile +++ b/mse-go-demo/c-server/Makefile @@ -1,6 +1,6 @@ REGISTRY ?= IMAGE_NAME ?= c-server -IMAGE_TAG ?= 0.1.0 +IMAGE_TAG ?= 1.0.0 IMG ?= ${REGISTRY}${IMAGE_NAME}:${IMAGE_TAG} docker-build: diff --git a/mse-go-demo/helm/mse-go-demo/.gitignore b/mse-go-demo/helm/mse-go-demo/.gitignore new file mode 100644 index 00000000..7a9d780c --- /dev/null +++ b/mse-go-demo/helm/mse-go-demo/.gitignore @@ -0,0 +1,2 @@ +/values.example.yaml + diff --git a/mse-go-demo/helm/mse-go-demo/Chart.yaml b/mse-go-demo/helm/mse-go-demo/Chart.yaml new file mode 100644 index 00000000..87cfc935 --- /dev/null +++ b/mse-go-demo/helm/mse-go-demo/Chart.yaml @@ -0,0 +1,8 @@ +apiVersion: v2 +name: mse-simple-demo +version: "1.0.0" +appVersion: "1.0.0" +home: https://mse.console.aliyun.com/ +keywords: + - mse + - category:microservice diff --git a/mse-go-demo/helm/mse-go-demo/README.md b/mse-go-demo/helm/mse-go-demo/README.md new file mode 100644 index 00000000..83731a31 --- /dev/null +++ b/mse-go-demo/helm/mse-go-demo/README.md @@ -0,0 +1,16 @@ +## build + +At directory `A`/`B`/`C`/`gateway`: + +* execute `./build.sh` to build image +* `docker tag` to tag image +* `docker push` to push image + +## install + +```shell +helm3 upgrade mse-simple-demo1 helm/mse-simple-demo \ + --namespace default --create-namespace \ + --install \ + --values helm/mse-simple-demo/values.example.yaml +``` diff --git a/mse-go-demo/helm/mse-go-demo/templates/a-server.yaml b/mse-go-demo/helm/mse-go-demo/templates/a-server.yaml new file mode 100644 index 00000000..2d854210 --- /dev/null +++ b/mse-go-demo/helm/mse-go-demo/templates/a-server.yaml @@ -0,0 +1,41 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: a-server + namespace: {{ .Release.Namespace }} +spec: + replicas: 1 + selector: + matchLabels: + app: a-server + template: + metadata: + labels: + msePilotAutoEnable: "on" + appName: "{{ .Values.mse.namePrefix }}a-server" + app: "a-server" + spec: + containers: + - name: a-server + image: "{{ .Values.registry }}a-server:1.0.0" + imagePullPolicy: Always + resources: + requests: + cpu: 250m + memory: 512Mi + limits: + cpu: 250m + memory: 512Mi + ports: + - name: port-1 + containerPort: 8080 + protocol: TCP + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + topologyKey: failure-domain.beta.kubernetes.io/zone + weight: 50 + - podAffinityTerm: + topologyKey: kubernetes.io/hostname + weight: 100 diff --git a/mse-go-demo/helm/mse-go-demo/templates/a-service.yaml b/mse-go-demo/helm/mse-go-demo/templates/a-service.yaml new file mode 100644 index 00000000..848aea40 --- /dev/null +++ b/mse-go-demo/helm/mse-go-demo/templates/a-service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + annotations: + service.beta.kubernetes.io/alibaba-cloud-loadbalancer-spec: slb.s1.small + service.beta.kubernetes.io/alicloud-loadbalancer-address-type: internet + name: go-a-service + namespace: {{ .Release.Namespace }} +spec: + ports: + - name: port-1 + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: a-server + type: LoadBalancer diff --git a/mse-go-demo/helm/mse-go-demo/templates/b-server.yaml b/mse-go-demo/helm/mse-go-demo/templates/b-server.yaml new file mode 100644 index 00000000..028f6d38 --- /dev/null +++ b/mse-go-demo/helm/mse-go-demo/templates/b-server.yaml @@ -0,0 +1,41 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: b-server + namespace: {{ .Release.Namespace }} +spec: + replicas: 1 + selector: + matchLabels: + app: b-server + template: + metadata: + labels: + msePilotAutoEnable: "on" + appName: "{{ .Values.mse.namePrefix }}b-server" + app: "b-server" + spec: + containers: + - name: b-server + image: "{{ .Values.registry }}b-server:1.0.0" + imagePullPolicy: Always + resources: + requests: + cpu: 250m + memory: 512Mi + limits: + cpu: 250m + memory: 512Mi + ports: + - name: port-1 + containerPort: 50051 + protocol: TCP + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + topologyKey: failure-domain.beta.kubernetes.io/zone + weight: 50 + - podAffinityTerm: + topologyKey: kubernetes.io/hostname + weight: 100 diff --git a/mse-go-demo/helm/mse-go-demo/templates/b-service.yaml b/mse-go-demo/helm/mse-go-demo/templates/b-service.yaml new file mode 100644 index 00000000..f7d89f6a --- /dev/null +++ b/mse-go-demo/helm/mse-go-demo/templates/b-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: go-b-service + namespace: default +spec: + ports: + - name: port-1 + port: 50051 + protocol: TCP + targetPort: 50051 + selector: + app: b-server + type: ClusterIP \ No newline at end of file diff --git a/mse-go-demo/helm/mse-go-demo/templates/c-server-gray.yaml b/mse-go-demo/helm/mse-go-demo/templates/c-server-gray.yaml new file mode 100644 index 00000000..ad597510 --- /dev/null +++ b/mse-go-demo/helm/mse-go-demo/templates/c-server-gray.yaml @@ -0,0 +1,42 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: c-server-gray + namespace: {{ .Release.Namespace }} +spec: + replicas: 1 + selector: + matchLabels: + app: c-server + template: + metadata: + labels: + alicloud.service.tag: gray + msePilotAutoEnable: "on" + appName: "{{ .Values.mse.namePrefix }}c-server" + app: "c-server" + spec: + containers: + - name: c-server + image: "{{ .Values.registry }}c-server:1.0.0" + imagePullPolicy: Always + resources: + requests: + cpu: 250m + memory: 512Mi + limits: + cpu: 250m + memory: 512Mi + ports: + - name: port-1 + containerPort: 50051 + protocol: TCP + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + topologyKey: failure-domain.beta.kubernetes.io/zone + weight: 50 + - podAffinityTerm: + topologyKey: kubernetes.io/hostname + weight: 100 diff --git a/mse-go-demo/helm/mse-go-demo/templates/c-server.yaml b/mse-go-demo/helm/mse-go-demo/templates/c-server.yaml new file mode 100644 index 00000000..85f801eb --- /dev/null +++ b/mse-go-demo/helm/mse-go-demo/templates/c-server.yaml @@ -0,0 +1,41 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: c-server + namespace: {{ .Release.Namespace }} +spec: + replicas: 1 + selector: + matchLabels: + app: c-server + template: + metadata: + labels: + msePilotAutoEnable: "on" + appName: "{{ .Values.mse.namePrefix }}c-server" + app: "c-server" + spec: + containers: + - name: c-server + image: "{{ .Values.registry }}c-server:1.0.0" + imagePullPolicy: Always + resources: + requests: + cpu: 250m + memory: 512Mi + limits: + cpu: 250m + memory: 512Mi + ports: + - name: port-1 + containerPort: 50051 + protocol: TCP + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - podAffinityTerm: + topologyKey: failure-domain.beta.kubernetes.io/zone + weight: 50 + - podAffinityTerm: + topologyKey: kubernetes.io/hostname + weight: 100 diff --git a/mse-go-demo/helm/mse-go-demo/templates/c-service.yaml b/mse-go-demo/helm/mse-go-demo/templates/c-service.yaml new file mode 100644 index 00000000..b9d869a6 --- /dev/null +++ b/mse-go-demo/helm/mse-go-demo/templates/c-service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: go-c-service + namespace: default +spec: + ports: + - name: port-1 + port: 50051 + protocol: TCP + targetPort: 50051 + selector: + app: c-server + type: ClusterIP \ No newline at end of file diff --git a/mse-go-demo/helm/mse-go-demo/values.yaml b/mse-go-demo/helm/mse-go-demo/values.yaml new file mode 100644 index 00000000..06bc65fc --- /dev/null +++ b/mse-go-demo/helm/mse-go-demo/values.yaml @@ -0,0 +1,5 @@ +# 镜像地址的前缀 +registry: registry.cn-shanghai.aliyuncs.com/yizhan/ + +mse: + namePrefix: luyanbo