Skip to content

The Go language implementation of Micro gRPC [Mirror]

License

Notifications You must be signed in to change notification settings

vaniila/go-grpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Micro gRPC License GoDoc Travis CI Go Report Card

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.

Getting Started

Install Protobuf

Protobuf is required for code generation

You'll need to install:

Service Discovery

Service discovery is used to resolve service names to addresses.

Consul

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.

mDNS

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

Writing a Service

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)
	}
}

Use with Micro

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

go get github.com/micro/grpc/cmd/micro

Build Yourself

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

Use with gRPC Gateway

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.

About

The Go language implementation of Micro gRPC [Mirror]

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages