karrybit / now

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Now count the time

Installation

$ go get -u github.com/golang/protobuf/{proto,protoc-gen-go}
$ go get -u google.golang.org/grpc

Generate gRPC client and server

syntax = "proto3";
package now;

option go_package = "pb/now";

import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";

service Now {
    rpc Tick(google.protobuf.Empty) returns (stream google.protobuf.Timestamp) {}
}

check protoc-gen-go and protoc-gen-go-grpc version.

$ ~/go/bin/protoc-gen-go --version
protoc-gen-go v1.26.0
$ ~/go/bin/protoc-gen-go-grpc --version
protoc-gen-go-grpc 1.0.1

generate 2 go files.

$ protoc --go_out=. --go-grpc_out=. proto/*.proto
# generated {go_package_path}/{proto_file_name}_grpc.pb.go
# generated {go_package_path}/{proto_file_name}.pb.go

Run

$ go run server/server.go
$ go run client/client.go

Reference

https://blog.golang.org/protobuf-apiv2

What I don't understand

Cannot find packages

I executed command below. Then I could build and run.

$ go mod tidy
$ go mod vendor

Relationship between installed package and command to be executed

I installed proto, protoc-gen-go and grpc, but I don't know which one I really needed.

About


Languages

Language:Go 100.0%