gateway

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAddr        = ":8888" //  默认地址
	DefaultGrpcAddr    = ":5001" //  默认grpc地址
	DefaultGrpcNetwork = "tcp"   //  默认grpc
	DefaultSwaggerDir  = "/swagger"
)

参考:https://github.com/grpc-ecosystem/grpc-gateway/tree/master/examples/gateway

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, options ...Option) error
开启一个网关服务
go gateway.Run(

ctx, gateway.WithAddr(":8888"), gateway.WithGRPCServer("tcp", ":5001"), gateway.WithSwaggerDir("/swagger"), gateway.WithHandle(pb.RegisterRbacServiceHandler), )

Run starts a HTTP server and blocks while running if successful.//  The server will be shutdown when "ctx" is canceled.

Types

type Endpoint

type Endpoint struct {
	Network, Addr string
}

Endpoint describes a gRPC endpoint

type Option

type Option func(*Options)

网关参数设置

func WithAddr

func WithAddr(addr string) Option

设置监听地址

func WithGRPCServer

func WithGRPCServer(network, addr string) Option

设置grpc服务地址

func WithHandle

func WithHandle(handle ...regHandle) Option

设置Handles

func WithMuxOption

func WithMuxOption(mux ...gwruntime.ServeMuxOption) Option

设置mux

func WithSwaggerDir

func WithSwaggerDir(dir string) Option

设置swagger目录

type Options

type Options struct {
	//  Addr is the address to listen
	Addr string

	//  GRPCServer defines an endpoint of a gRPC service
	GRPCServer Endpoint

	//  SwaggerDir is a path to a directory from which the server
	//  serves swagger specs.
	SwaggerDir string

	//  Mux is a list of options to be passed to the grpc-gateway multiplexer
	Mux []gwruntime.ServeMuxOption

	//  注册
	Handles []regHandle
}

Options is a set of options to be passed to Run

Jump to

Keyboard shortcuts

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