grpc

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

Go GRPC License GoDoc Travis CI Go Report Card

Go-GRPC is a micro based gRPC framework for microservices.

Go-GRPC provides a go-micro.Service leveraging gRPC plugins for the client, server and transport. Go-GRPC shares the go-micro codebase, making it a pluggable gRPC framework for microservices. Everything works just like a go-micro service, using micro generated protobufs and defaulting to consul for service discovery.

Go-GRPC interoperates with standard gRPC services seamlessly.

Find an example greeter service in examples/greeter.

Writing a Micro Service

Initialisation of a 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 (
	"log"
	"time"

	"github.com/micro/go-grpc"
	"github.com/micro/go-micro"
	hello "github.com/micro/go-grpc/examples/greeter/server/proto/hello"

	"golang.org/x/net/context"
)

type Say struct{}

func (s *Say) Hello(ctx context.Context, req *hello.Request, rsp *hello.Response) error {
	log.Print("Received Say.Hello request")
	rsp.Msg = "Hello " + req.Name
	return nil
}

func main() {
	service := grpc.NewService(
		micro.Name("go.micro.srv.greeter"),
		micro.RegisterTTL(time.Second*30),
		micro.RegisterInterval(time.Second*10),
	)

	// optionally setup command line usage
	service.Init()

	// Register Handlers
	hello.RegisterSayHandler(service.Server(), new(Say))

	// Run server
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFunction

func NewFunction(opts ...micro.Option) micro.Function

NewFunction returns a grpc service compatible with go-micro.Function

func NewService

func NewService(opts ...micro.Option) micro.Service

NewService returns a grpc service compatible with go-micro.Service

Types

This section is empty.

Jump to

Keyboard shortcuts

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