gateway

command
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

GRPC

Contains examples for using go-grpc

New service

Check out the greeter example using go-grpc

Import go-grpc
import "github.com/micro/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/micro/go-micro/client"
	"github.com/micro/go-micro/server"
	cli "github.com/micro/go-plugins/client/grpc"
	srv "github.com/micro/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

GRPC Gateway

gateway目录主要处理url访问的请求,通过grpc转发给对应的业务greeter,并返回相对应的结果。 grpc-gateway的架构介绍 项目代码参考grpc-ecosystem/grpc-gateway.
这部分依赖三个库

  • protoc-gen-grpc-gateway
  • protoc-gen-grpc-swagger
  • protoc-gen-go

这三个目录在tools/framework_install.sh, 该脚本已经安装过,可以前往GOBIN目录查看,确定安装成功后

Services written with micro/go-grpc are fully compatible with the grpc-gateway and any other grpc services.

Usage

Run the go.micro.srv.greeter service

go run ../greeter/srv/main.go --server_address=localhost:9090

Run the gateway

go run main.go

Curl your request at the gateway (localhost:8080)

curl -d '{"name": "evan"}' http://localhost:8080/greeter/hello

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
proto

Jump to

Keyboard shortcuts

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