gRPC is an open-source, high-performance, general RPC framework that uses HTTP/2. It is the Golang (Go) implementation of gRPC.
Remote Procedure Call (RPC) is a distributed computing technique in which a computer program calls a procedure to execute in a different address space than its own. The RPC frameworks handle how that remote interaction is carried out.
$ go get -u google.golang.org/grpc
import "google.golang.org/grpc"
Here is an example of a simple gRPC server that listens on the 5000
port. The server does not do much, but we can add functionality by defining .proto
files and generate the Go specific gRPC code using a Protocol Buffers tool.
package mainimport ("log""net""google.golang.org/grpc")func main() {// Setting up a tcp connection on port 5000listener, error := net.Listen("tcp", ":5000")if error != nil {log.Fatalf("Failed to listen: %v", err)}// Creating the gRPC servergrpcServer := grpc.NewServer()// Serving on the listenererr := grpcServer.Serve(listener);if err != nil {log.Fatalf("Failed to serve: %s", err)}}
You can read the entire gRPC API here.