├── proto └── echo.proto ├── .gitignore ├── .gitpod.yml ├── go.mod ├── internal ├── service │ └── echo.go └── pb │ ├── echo_grpc.pb.go │ └── echo.pb.go ├── LICENSE ├── cmd ├── server │ └── server.go └── client │ └── client.go ├── Taskfile.yml ├── go.sum └── README.md /proto/echo.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package echo; 4 | option go_package = "internal/pb"; 5 | 6 | service Echo { 7 | rpc Echo (EchoMessage) returns (EchoResponse) {} 8 | } 9 | 10 | message EchoMessage { 11 | string data = 1; 12 | } 13 | 14 | message EchoResponse { 15 | string data = 1; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | 17 | bin/ 18 | text-files/ 19 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: gitpod/workspace-go:latest 2 | 3 | tasks: 4 | - name: install staticcheck 5 | init: go install honnef.co/go/tools/cmd/staticcheck@latest 6 | - name: install go-task 7 | init: go install github.com/go-task/task/v3/cmd/task@latest 8 | - name: install goimport 9 | init: go install golang.org/x/tools/cmd/goimports@latest 10 | 11 | vscode: 12 | extensions: 13 | - golang.go 14 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/devlights/go-grpc-uds-example 2 | 3 | go 1.19 4 | 5 | require ( 6 | google.golang.org/grpc v1.52.0 7 | google.golang.org/protobuf v1.28.1 8 | ) 9 | 10 | require ( 11 | github.com/golang/protobuf v1.5.2 // indirect 12 | golang.org/x/net v0.5.0 // indirect 13 | golang.org/x/sys v0.4.0 // indirect 14 | golang.org/x/text v0.6.0 // indirect 15 | google.golang.org/genproto v0.0.0-20230119192704-9d59e20e5cd1 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /internal/service/echo.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "context" 5 | "strings" 6 | 7 | "github.com/devlights/go-grpc-uds-example/internal/pb" 8 | ) 9 | 10 | type EchoServiceImpl struct { 11 | } 12 | 13 | var _ pb.EchoServer = (*EchoServiceImpl)(nil) 14 | 15 | func NewEchoService() pb.EchoServer { 16 | return new(EchoServiceImpl) 17 | } 18 | 19 | func (e *EchoServiceImpl) Echo(ctx context.Context, message *pb.EchoMessage) (*pb.EchoResponse, error) { 20 | s := strings.ToUpper(message.Data) 21 | r := &pb.EchoResponse{ 22 | Data: s, 23 | } 24 | 25 | return r, nil 26 | } 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 devlights 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cmd/server/server.go: -------------------------------------------------------------------------------- 1 | // gRPC with Unix Domain Socket example (server side) 2 | // 3 | // # REFERENCES 4 | // - https://qiita.com/marnie_ms4/items/4582a1a0db363fe246f3 5 | // - http://yamahiro0518.hatenablog.com/entry/2016/02/01/215908 6 | // - https://zenn.dev/hsaki/books/golang-grpc-starting/viewer/client 7 | // - https://stackoverflow.com/a/46279623 8 | // - https://stackoverflow.com/a/18479916 9 | // - https://qiita.com/hnakamur/items/848097aad846d40ae84b 10 | 11 | package main 12 | 13 | import ( 14 | "log" 15 | "net" 16 | "os" 17 | 18 | "github.com/devlights/go-grpc-uds-example/internal/pb" 19 | "github.com/devlights/go-grpc-uds-example/internal/service" 20 | "google.golang.org/grpc" 21 | ) 22 | 23 | const ( 24 | protocol = "unix" 25 | sockAddr = "/tmp/echo.sock" 26 | ) 27 | 28 | func main() { 29 | if _, err := os.Stat(sockAddr); !os.IsNotExist(err) { 30 | if err := os.RemoveAll(sockAddr); err != nil { 31 | log.Fatal(err) 32 | } 33 | } 34 | 35 | listener, err := net.Listen(protocol, sockAddr) 36 | if err != nil { 37 | log.Fatal(err) 38 | } 39 | 40 | server := grpc.NewServer() 41 | echo := service.NewEchoService() 42 | 43 | pb.RegisterEchoServer(server, echo) 44 | 45 | server.Serve(listener) 46 | } 47 | -------------------------------------------------------------------------------- /Taskfile.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | tasks: 4 | install-requirements: 5 | desc: install requirements 6 | cmds: 7 | - mkdir tmp 8 | - task: _download-protoc 9 | - task: _unzip-protoc 10 | - mkdir -p bin 11 | - rm -rf bin/protoc 12 | - task: _locate-protoc 13 | - rm -rf ./tmp 14 | - go install google.golang.org/protobuf/cmd/protoc-gen-go@latest 15 | - go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest 16 | - rm -rf ./text-files; git clone --quiet https://github.com/devlights/text-files 17 | _download-protoc: 18 | dir: tmp 19 | cmds: 20 | - curl -L https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-linux-x86_64.zip --output protoc.zip 21 | _unzip-protoc: 22 | dir: tmp 23 | cmds: 24 | - unzip ./protoc.zip -d protoc 25 | _locate-protoc: 26 | dir: tmp 27 | cmds: 28 | - mv -f ./protoc/ ../bin 29 | protoc: 30 | desc: gen protoc 31 | cmds: 32 | - mkdir -p internal 33 | - bin/protoc/bin/protoc --go_out=. --go-grpc_out=require_unimplemented_servers=false:. proto/*.proto 34 | run: 35 | desc: run 36 | cmds: 37 | - go run cmd/server/server.go & 38 | - sleep 1 39 | - time go run cmd/client/client.go 40 | - sleep 1 41 | - pkill server 42 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 2 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= 3 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 4 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 5 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 6 | golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= 7 | golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= 8 | golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= 9 | golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 10 | golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= 11 | golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 12 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 13 | google.golang.org/genproto v0.0.0-20230119192704-9d59e20e5cd1 h1:wSjSSQW7LuPdv3m1IrSN33nVxH/kID6OIKy+FMwGB2k= 14 | google.golang.org/genproto v0.0.0-20230119192704-9d59e20e5cd1/go.mod h1:RGgjbofJ8xD9Sq1VVhDM1Vok1vRONV+rg+CjzG4SZKM= 15 | google.golang.org/grpc v1.52.0 h1:kd48UiU7EHsV4rnLyOJRuP/Il/UHE7gdDAQ+SZI7nZk= 16 | google.golang.org/grpc v1.52.0/go.mod h1:pu6fVzoFb+NBYNAvQL08ic+lvB2IojljRYuun5vorUY= 17 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 18 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 19 | google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= 20 | google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 21 | -------------------------------------------------------------------------------- /cmd/client/client.go: -------------------------------------------------------------------------------- 1 | // gRPC with Unix Domain Socket example (client side) 2 | // 3 | // # REFERENCES 4 | // - https://qiita.com/marnie_ms4/items/4582a1a0db363fe246f3 5 | // - http://yamahiro0518.hatenablog.com/entry/2016/02/01/215908 6 | // - https://zenn.dev/hsaki/books/golang-grpc-starting/viewer/client 7 | // - https://stackoverflow.com/a/46279623 8 | // - https://stackoverflow.com/a/18479916 9 | 10 | package main 11 | 12 | import ( 13 | "bufio" 14 | "context" 15 | "fmt" 16 | "io" 17 | "log" 18 | "net" 19 | "os" 20 | "time" 21 | 22 | "github.com/devlights/go-grpc-uds-example/internal/pb" 23 | "google.golang.org/grpc" 24 | "google.golang.org/grpc/credentials/insecure" 25 | ) 26 | 27 | const ( 28 | protocol = "unix" 29 | sockAddr = "/tmp/echo.sock" 30 | ) 31 | 32 | func main() { 33 | var ( 34 | rootCtx = context.Background() 35 | mainCtx, mainCxl = context.WithCancel(rootCtx) 36 | ) 37 | defer mainCxl() 38 | 39 | // 40 | // Connect 41 | // 42 | var ( 43 | credentials = insecure.NewCredentials() // No SSL/TLS 44 | dialer = func(ctx context.Context, addr string) (net.Conn, error) { 45 | var d net.Dialer 46 | return d.DialContext(ctx, protocol, addr) 47 | } 48 | options = []grpc.DialOption{ 49 | grpc.WithTransportCredentials(credentials), 50 | grpc.WithBlock(), 51 | grpc.WithContextDialer(dialer), 52 | } 53 | ) 54 | 55 | conn, err := grpc.Dial(sockAddr, options...) 56 | if err != nil { 57 | panic(err) 58 | } 59 | defer conn.Close() 60 | 61 | // 62 | // Send & Recv 63 | // 64 | var ( 65 | client = pb.NewEchoClient(conn) 66 | file = func() *os.File { 67 | f, err := os.Open("text-files/agatha_complete.txt") 68 | if err != nil { 69 | panic(err) 70 | } 71 | return f 72 | }() 73 | values = func(r io.ReadCloser) <-chan string { 74 | ch := make(chan string) 75 | go func() { 76 | defer r.Close() 77 | defer close(ch) 78 | scanner := bufio.NewScanner(r) 79 | for scanner.Scan() { 80 | ch <- scanner.Text() 81 | } 82 | }() 83 | return ch 84 | }(file) 85 | ) 86 | 87 | for v := range values { 88 | func() { 89 | ctx, cancel := context.WithTimeout(mainCtx, 1*time.Second) 90 | defer cancel() 91 | 92 | message := pb.EchoMessage{Data: v} 93 | 94 | res, err := client.Echo(ctx, &message) 95 | if err != nil { 96 | log.Println(err) 97 | return 98 | } 99 | 100 | fmt.Println(res) 101 | }() 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-grpc-uds-example 2 | gRPC with Unix domain socket (UDS) example by golang 3 | 4 | It can be executed using [go-task](https://taskfile.dev/#/). 5 | 6 | ```sh 7 | $ task --list 8 | task: Available tasks for this project: 9 | * install-requirements: install requirements 10 | * protoc: gen protoc 11 | * run: run 12 | ``` 13 | 14 | ## Install gRPC and Go libraries 15 | 16 | ```sh 17 | task install-requirements 18 | ``` 19 | 20 | ## Run protoc 21 | 22 | ```sh 23 | task protoc 24 | ``` 25 | 26 | ## Run Server and Client 27 | 28 | ```sh 29 | task run 30 | ``` 31 | 32 | ## Example 33 | 34 | ```sh 35 | $ task install-requirements 36 | task: [install-requirements] mkdir tmp 37 | task: [_download-protoc] curl -L https://github.com/protocolbuffers/protobuf/releases/download/v21.12/protoc-21.12-linux-x86_64.zip --output protoc.zip 38 | % Total % Received % Xferd Average Speed Time Time Time Current 39 | Dload Upload Total Spent Left Speed 40 | 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 41 | 100 1548k 100 1548k 0 0 4254k 0 --:--:-- --:--:-- --:--:-- 4254k 42 | task: [_unzip-protoc] unzip ./protoc.zip -d protoc 43 | Archive: ./protoc.zip 44 | inflating: protoc/bin/protoc 45 | inflating: protoc/include/google/protobuf/any.proto 46 | inflating: protoc/include/google/protobuf/api.proto 47 | inflating: protoc/include/google/protobuf/compiler/plugin.proto 48 | inflating: protoc/include/google/protobuf/descriptor.proto 49 | inflating: protoc/include/google/protobuf/duration.proto 50 | inflating: protoc/include/google/protobuf/empty.proto 51 | inflating: protoc/include/google/protobuf/field_mask.proto 52 | inflating: protoc/include/google/protobuf/source_context.proto 53 | inflating: protoc/include/google/protobuf/struct.proto 54 | inflating: protoc/include/google/protobuf/timestamp.proto 55 | inflating: protoc/include/google/protobuf/type.proto 56 | inflating: protoc/include/google/protobuf/wrappers.proto 57 | inflating: protoc/readme.txt 58 | task: [install-requirements] mkdir -p bin 59 | task: [install-requirements] rm -rf bin/protoc 60 | task: [_locate-protoc] mv -f ./protoc/ ../bin 61 | task: [install-requirements] rm -rf ./tmp 62 | task: [install-requirements] go install google.golang.org/protobuf/cmd/protoc-gen-go@latest 63 | task: [install-requirements] go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest 64 | task: [install-requirements] rm -rf ./text-files; git clone --quiet https://github.com/devlights/text-files 65 | 66 | 67 | $ task protoc 68 | task: [protoc] mkdir -p internal 69 | task: [protoc] bin/protoc/bin/protoc --go_out=. --go-grpc_out=require_unimplemented_servers=false:. proto/*.proto 70 | 71 | 72 | $ task run 73 | task: [run] go run cmd/server/server.go & 74 | task: [run] sleep 1 75 | task: [run] go run cmd/client/client.go 76 | data:"HELLO WORLD" 77 | data:"GOLANG" 78 | data:"GOROUTINE" 79 | data:"THIS PROGRAM RUNS ON CROSTINI" 80 | task: [run] sleep 1 81 | task: [run] pkill server 82 | signal: terminated 83 | ``` -------------------------------------------------------------------------------- /internal/pb/echo_grpc.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go-grpc. DO NOT EDIT. 2 | // versions: 3 | // - protoc-gen-go-grpc v1.2.0 4 | // - protoc v3.21.12 5 | // source: proto/echo.proto 6 | 7 | package pb 8 | 9 | import ( 10 | context "context" 11 | grpc "google.golang.org/grpc" 12 | codes "google.golang.org/grpc/codes" 13 | status "google.golang.org/grpc/status" 14 | ) 15 | 16 | // This is a compile-time assertion to ensure that this generated file 17 | // is compatible with the grpc package it is being compiled against. 18 | // Requires gRPC-Go v1.32.0 or later. 19 | const _ = grpc.SupportPackageIsVersion7 20 | 21 | // EchoClient is the client API for Echo service. 22 | // 23 | // 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. 24 | type EchoClient interface { 25 | Echo(ctx context.Context, in *EchoMessage, opts ...grpc.CallOption) (*EchoResponse, error) 26 | } 27 | 28 | type echoClient struct { 29 | cc grpc.ClientConnInterface 30 | } 31 | 32 | func NewEchoClient(cc grpc.ClientConnInterface) EchoClient { 33 | return &echoClient{cc} 34 | } 35 | 36 | func (c *echoClient) Echo(ctx context.Context, in *EchoMessage, opts ...grpc.CallOption) (*EchoResponse, error) { 37 | out := new(EchoResponse) 38 | err := c.cc.Invoke(ctx, "/echo.Echo/Echo", in, out, opts...) 39 | if err != nil { 40 | return nil, err 41 | } 42 | return out, nil 43 | } 44 | 45 | // EchoServer is the server API for Echo service. 46 | // All implementations should embed UnimplementedEchoServer 47 | // for forward compatibility 48 | type EchoServer interface { 49 | Echo(context.Context, *EchoMessage) (*EchoResponse, error) 50 | } 51 | 52 | // UnimplementedEchoServer should be embedded to have forward compatible implementations. 53 | type UnimplementedEchoServer struct { 54 | } 55 | 56 | func (UnimplementedEchoServer) Echo(context.Context, *EchoMessage) (*EchoResponse, error) { 57 | return nil, status.Errorf(codes.Unimplemented, "method Echo not implemented") 58 | } 59 | 60 | // UnsafeEchoServer may be embedded to opt out of forward compatibility for this service. 61 | // Use of this interface is not recommended, as added methods to EchoServer will 62 | // result in compilation errors. 63 | type UnsafeEchoServer interface { 64 | mustEmbedUnimplementedEchoServer() 65 | } 66 | 67 | func RegisterEchoServer(s grpc.ServiceRegistrar, srv EchoServer) { 68 | s.RegisterService(&Echo_ServiceDesc, srv) 69 | } 70 | 71 | func _Echo_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { 72 | in := new(EchoMessage) 73 | if err := dec(in); err != nil { 74 | return nil, err 75 | } 76 | if interceptor == nil { 77 | return srv.(EchoServer).Echo(ctx, in) 78 | } 79 | info := &grpc.UnaryServerInfo{ 80 | Server: srv, 81 | FullMethod: "/echo.Echo/Echo", 82 | } 83 | handler := func(ctx context.Context, req interface{}) (interface{}, error) { 84 | return srv.(EchoServer).Echo(ctx, req.(*EchoMessage)) 85 | } 86 | return interceptor(ctx, in, info, handler) 87 | } 88 | 89 | // Echo_ServiceDesc is the grpc.ServiceDesc for Echo service. 90 | // It's only intended for direct use with grpc.RegisterService, 91 | // and not to be introspected or modified (even as a copy) 92 | var Echo_ServiceDesc = grpc.ServiceDesc{ 93 | ServiceName: "echo.Echo", 94 | HandlerType: (*EchoServer)(nil), 95 | Methods: []grpc.MethodDesc{ 96 | { 97 | MethodName: "Echo", 98 | Handler: _Echo_Echo_Handler, 99 | }, 100 | }, 101 | Streams: []grpc.StreamDesc{}, 102 | Metadata: "proto/echo.proto", 103 | } 104 | -------------------------------------------------------------------------------- /internal/pb/echo.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.28.1 4 | // protoc v3.21.12 5 | // source: proto/echo.proto 6 | 7 | package pb 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type EchoMessage struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` 29 | } 30 | 31 | func (x *EchoMessage) Reset() { 32 | *x = EchoMessage{} 33 | if protoimpl.UnsafeEnabled { 34 | mi := &file_proto_echo_proto_msgTypes[0] 35 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 36 | ms.StoreMessageInfo(mi) 37 | } 38 | } 39 | 40 | func (x *EchoMessage) String() string { 41 | return protoimpl.X.MessageStringOf(x) 42 | } 43 | 44 | func (*EchoMessage) ProtoMessage() {} 45 | 46 | func (x *EchoMessage) ProtoReflect() protoreflect.Message { 47 | mi := &file_proto_echo_proto_msgTypes[0] 48 | if protoimpl.UnsafeEnabled && x != nil { 49 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 50 | if ms.LoadMessageInfo() == nil { 51 | ms.StoreMessageInfo(mi) 52 | } 53 | return ms 54 | } 55 | return mi.MessageOf(x) 56 | } 57 | 58 | // Deprecated: Use EchoMessage.ProtoReflect.Descriptor instead. 59 | func (*EchoMessage) Descriptor() ([]byte, []int) { 60 | return file_proto_echo_proto_rawDescGZIP(), []int{0} 61 | } 62 | 63 | func (x *EchoMessage) GetData() string { 64 | if x != nil { 65 | return x.Data 66 | } 67 | return "" 68 | } 69 | 70 | type EchoResponse struct { 71 | state protoimpl.MessageState 72 | sizeCache protoimpl.SizeCache 73 | unknownFields protoimpl.UnknownFields 74 | 75 | Data string `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` 76 | } 77 | 78 | func (x *EchoResponse) Reset() { 79 | *x = EchoResponse{} 80 | if protoimpl.UnsafeEnabled { 81 | mi := &file_proto_echo_proto_msgTypes[1] 82 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 83 | ms.StoreMessageInfo(mi) 84 | } 85 | } 86 | 87 | func (x *EchoResponse) String() string { 88 | return protoimpl.X.MessageStringOf(x) 89 | } 90 | 91 | func (*EchoResponse) ProtoMessage() {} 92 | 93 | func (x *EchoResponse) ProtoReflect() protoreflect.Message { 94 | mi := &file_proto_echo_proto_msgTypes[1] 95 | if protoimpl.UnsafeEnabled && x != nil { 96 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 97 | if ms.LoadMessageInfo() == nil { 98 | ms.StoreMessageInfo(mi) 99 | } 100 | return ms 101 | } 102 | return mi.MessageOf(x) 103 | } 104 | 105 | // Deprecated: Use EchoResponse.ProtoReflect.Descriptor instead. 106 | func (*EchoResponse) Descriptor() ([]byte, []int) { 107 | return file_proto_echo_proto_rawDescGZIP(), []int{1} 108 | } 109 | 110 | func (x *EchoResponse) GetData() string { 111 | if x != nil { 112 | return x.Data 113 | } 114 | return "" 115 | } 116 | 117 | var File_proto_echo_proto protoreflect.FileDescriptor 118 | 119 | var file_proto_echo_proto_rawDesc = []byte{ 120 | 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 121 | 0x74, 0x6f, 0x12, 0x04, 0x65, 0x63, 0x68, 0x6f, 0x22, 0x21, 0x0a, 0x0b, 0x45, 0x63, 0x68, 0x6f, 122 | 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 123 | 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x22, 0x0a, 0x0c, 0x45, 124 | 0x63, 0x68, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 125 | 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x32, 126 | 0x37, 0x0a, 0x04, 0x45, 0x63, 0x68, 0x6f, 0x12, 0x2f, 0x0a, 0x04, 0x45, 0x63, 0x68, 0x6f, 0x12, 127 | 0x11, 0x2e, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x4d, 0x65, 0x73, 0x73, 0x61, 128 | 0x67, 0x65, 0x1a, 0x12, 0x2e, 0x65, 0x63, 0x68, 0x6f, 0x2e, 0x45, 0x63, 0x68, 0x6f, 0x52, 0x65, 129 | 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0d, 0x5a, 0x0b, 0x69, 0x6e, 0x74, 0x65, 130 | 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 131 | } 132 | 133 | var ( 134 | file_proto_echo_proto_rawDescOnce sync.Once 135 | file_proto_echo_proto_rawDescData = file_proto_echo_proto_rawDesc 136 | ) 137 | 138 | func file_proto_echo_proto_rawDescGZIP() []byte { 139 | file_proto_echo_proto_rawDescOnce.Do(func() { 140 | file_proto_echo_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_echo_proto_rawDescData) 141 | }) 142 | return file_proto_echo_proto_rawDescData 143 | } 144 | 145 | var file_proto_echo_proto_msgTypes = make([]protoimpl.MessageInfo, 2) 146 | var file_proto_echo_proto_goTypes = []interface{}{ 147 | (*EchoMessage)(nil), // 0: echo.EchoMessage 148 | (*EchoResponse)(nil), // 1: echo.EchoResponse 149 | } 150 | var file_proto_echo_proto_depIdxs = []int32{ 151 | 0, // 0: echo.Echo.Echo:input_type -> echo.EchoMessage 152 | 1, // 1: echo.Echo.Echo:output_type -> echo.EchoResponse 153 | 1, // [1:2] is the sub-list for method output_type 154 | 0, // [0:1] is the sub-list for method input_type 155 | 0, // [0:0] is the sub-list for extension type_name 156 | 0, // [0:0] is the sub-list for extension extendee 157 | 0, // [0:0] is the sub-list for field type_name 158 | } 159 | 160 | func init() { file_proto_echo_proto_init() } 161 | func file_proto_echo_proto_init() { 162 | if File_proto_echo_proto != nil { 163 | return 164 | } 165 | if !protoimpl.UnsafeEnabled { 166 | file_proto_echo_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 167 | switch v := v.(*EchoMessage); i { 168 | case 0: 169 | return &v.state 170 | case 1: 171 | return &v.sizeCache 172 | case 2: 173 | return &v.unknownFields 174 | default: 175 | return nil 176 | } 177 | } 178 | file_proto_echo_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 179 | switch v := v.(*EchoResponse); i { 180 | case 0: 181 | return &v.state 182 | case 1: 183 | return &v.sizeCache 184 | case 2: 185 | return &v.unknownFields 186 | default: 187 | return nil 188 | } 189 | } 190 | } 191 | type x struct{} 192 | out := protoimpl.TypeBuilder{ 193 | File: protoimpl.DescBuilder{ 194 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 195 | RawDescriptor: file_proto_echo_proto_rawDesc, 196 | NumEnums: 0, 197 | NumMessages: 2, 198 | NumExtensions: 0, 199 | NumServices: 1, 200 | }, 201 | GoTypes: file_proto_echo_proto_goTypes, 202 | DependencyIndexes: file_proto_echo_proto_depIdxs, 203 | MessageInfos: file_proto_echo_proto_msgTypes, 204 | }.Build() 205 | File_proto_echo_proto = out.File 206 | file_proto_echo_proto_rawDesc = nil 207 | file_proto_echo_proto_goTypes = nil 208 | file_proto_echo_proto_depIdxs = nil 209 | } 210 | --------------------------------------------------------------------------------