grpc/

directory
v0.0.0-...-2897420 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2018 License: Apache-2.0

README

GRPC

Contains examples for using go-grpc

  • greeter - A greeter example
  • gateway - A grpc gateway example
  • sidecar - Using the micro sidecar for http

New service

Check out the greeter example using go-grpc

Import go-grpc
import "github.com/jinbanglin/go-grpc"
Create micro.Service
service := grpc.NewService()

Pre-existing Service

What if you want to add grpc to a pre-existing service? Use the build pattern for plugins but swap out the client/server.

Create a plugin file
package main

import (
	"github.com/jinbanglin/go-micro/client"
	"github.com/jinbanglin/go-micro/server"
	cli "github.com/jinbanglin/go-plugins/client/grpc"
	srv "github.com/jinbanglin/go-plugins/server/grpc"
)

func init() {
	// set the default client
	client.DefaultClient = cli.NewClient()
	// set the default server
	server.DefaultServer = srv.NewServer()
}
Build the binary
// For local use
go build -i -o service ./main.go ./plugins.go
Run

Because the default client/server have been replaced we can just run as usual

./service

Directories

Path Synopsis
proto/hello
Package greeter is a generated protocol buffer package.
Package greeter is a generated protocol buffer package.
greeter
cli
srv
srv/proto/hello
Package go_micro_srv_greeter is a generated protocol buffer package.
Package go_micro_srv_greeter is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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