This is a micro gRPC framework. A simplified experience for building gRPC services.
Go-grpc makes use of go-micro plugins to create a better framework for gRPC development. It interoperates with standard gRPC services seamlessly, including the grpc-gateway.
Find an example greeter service in examples/greeter.
Protobuf is required for code generation
You'll need to install:
Service discovery is used to resolve service names to addresses.
Consul is used as the default service discovery system. See the install guide.
Discovery is pluggable. Find plugins for etcd, kubernetes, zookeeper and more in the micro/go-plugins repo.
Multicast DNS is a built in alternative for zero dependencies.
Pass --registry=mdns
to any command or the enviroment variable MICRO_REGISTRY=mdns
MICRO_REGISTRY=mdns go run main.go
Go-grpc service is identical to a go-micro service. Which means you can swap out micro.NewService
for grpc.NewService
with zero other code changes.
package main
import (
"context"
"time"
"github.com/micro/go-grpc"
"github.com/micro/go-micro"
hello "github.com/micro/go-grpc/examples/greeter/server/proto/hello"
)
type Say struct{}
func (s *Say) Hello(ctx context.Context, req *hello.Request, rsp *hello.Response) error {
rsp.Msg = "Hello " + req.Name
return nil
}
func main() {
service := grpc.NewService(
micro.Name("greeter"),
)
service.Init()
hello.RegisterSayHandler(service.Server(), new(Say))
if err := service.Run(); err != nil {
log.Fatal(err)
}
}
You may want to use the micro toolkit with grpc services. To do this either use the prebuilt toolkit or simply include the grpc client plugin and rebuild the toolkit.
go get github.com/micro/grpc/cmd/micro
go get github.com/micro/micro
Create a plugins.go file
package main
import _ "github.com/micro/go-plugins/client/grpc"
import _ "github.com/micro/go-plugins/server/grpc"
Build binary
// For local use
go build -i -o micro ./main.go ./plugins.go
Flag usage of plugins
micro --client=grpc --server=grpc
Go-grpc seamlessly integrates with the gRPC ecosystem. This means the grpc-gateway can be used as per usual.
Find an example greeter api at examples/grpc/gateway.