# README
-
protoc --go_out=. test.proto
-
.proto => .pb.gos
-
option go_package = "github.com/golang/protobuf/p"; instead of package example;
- protoc --go_out=. example/test.proto
- protoc --go_out=paths=source_relative:. example/test.prot-o
[Note] paths=[import|source_relative]
Attention!!! --proto_path=<> is very useful e.g. protoc --proto_path=example --go_out=pkg test.proto
- If a proto file specifies RPC services, protoc-gen-go can be instructed to generate code compatible with gRPC protoc --go_out=plugins=grpc,paths=source_relative:. example/test.proto
[Note] plugins=grpc
- For grpc service
- For client, define interface and implement those functions
- For server, only define interface BTW, there is register function like 'RegisterAPIServiceServer'
- create client and server
- client conn, err := grpc.Dial(*address, grpc.WithInsecure()) // *grpc.ClientConn defer conn.Close()
c := v1.NewToDoServiceClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() [Note] ctx is used to call server function
- server server := grpc.NewServer() v1.RegisterToDoServiceServer(server, v1API)
listen, err := net.Listen("tcp", ":"+port) server.Serve(listen)
- HTTP <=> GRPC using github.com/grpc-ecosystem/grpc-gateway protoc --proto_path=api/proto/v1 --proto_path=third_party --grpc-gateway_out=logtostderr=true:pkg/api/v1 todo-service.proto
# Packages
No description provided by the author