00-grpc/

directory
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2024 License: MIT

README

Goal

Create gRPC Server and Client in Go. We will create a fictional blockchain service.

Steps

  • Install protoc compiler.
  • Install protoc-gen-go plugin: go get -u github.com/golang/protobuf/protoc-gen-go
  • Define service definition in .proto file.
  • Build Go bindings from .proto file. protoc --go_out=plugins=grpc:. proto/blockchain.proto
  • Install grpc Go package - go get -u google.golang.org/grpc.
  • Install context package - go get -u golang.org/x/net/context.
  • Install protobuf package - go get -u github.com/golang/protobuf/proto
  • Implement Server, interface BlockchainServer.
  • Create a client using BlockchainClient.
  • Run server first.
  • Run client.

Usage

Start server:

go run server/main.go

Add block as client:

go run client/main.go --add

get blockchain as client:

go run client/main.go --list

Directories

Path Synopsis
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL