grapiserver

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2018 License: MIT Imports: 16 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfig is a default configuration.
	DefaultConfig = &Config{
		GrpcInternalAddr: &Address{
			Network: "unix",
			Addr:    "tmp/server.sock",
		},
		GatewayAddr: &Address{
			Network: "tcp",
			Addr:    ":3000",
		},
		MaxConcurrentStreams: 1000,
		Logger:               DefaultLogger,
	}
)

Functions

This section is empty.

Types

type Address

type Address struct {
	Network string
	Addr    string
}

Address represents a network end point address.

type Builder

type Builder interface {
	SetGrpcInternalAddr(network, addr string) Builder
	SetGatewayAddr(network, addr string) Builder
	AddGrpcServerUnaryInterceptors(interceptors ...grpc.UnaryServerInterceptor) Builder
	AddGrpcServerStreamInterceptors(interceptors ...grpc.StreamServerInterceptor) Builder
	AddGatewayServerUnaryInterceptors(interceptors ...grpc.UnaryClientInterceptor) Builder
	AddGatewayServerStreamInterceptors(interceptors ...grpc.StreamClientInterceptor) Builder
	AddRegisterGrpcServerImplFuncs(registerFuncs ...RegisterGrpcServerImplFunc) Builder
	AddRegisterGatewayHandlerFuncs(registerFuncs ...RegisterGatewayHandlerFunc) Builder
	AddGatewayMuxOptions(opts ...runtime.ServeMuxOption) Builder
	AddGatewayServerMiddleware(middlewares ...HTTPServerMiddleware) Builder
	AddPassedHeader(decider PassedHeaderDeciderFunc) Builder
	SetLogger(l Logger) Builder
	Validate() error
	Build() (*Engine, error)
	Serve() error
}

Builder creates an engine.

func New

func New() Builder

New creates a server builder object.

type Config

type Config struct {
	GrpcInternalAddr                *Address
	GatewayAddr                     *Address
	RegisterGrpcServerImplFuncs     []RegisterGrpcServerImplFunc
	RegisterGatewayHandlerFuncs     []RegisterGatewayHandlerFunc
	GrpcServerUnaryInterceptors     []grpc.UnaryServerInterceptor
	GrpcServerStreamInterceptors    []grpc.StreamServerInterceptor
	GatewayServerUnaryInterceptors  []grpc.UnaryClientInterceptor
	GatewayServerStreamInterceptors []grpc.StreamClientInterceptor
	GatewayMuxOptions               []runtime.ServeMuxOption
	MaxConcurrentStreams            uint32
	Logger                          Logger
	GatewayServerMiddlewares        []HTTPServerMiddleware
}

Config contains configurations of gRPC and Gateway server.

type Engine

type Engine struct {
	*Config
}

Engine is the framework instance.

func (*Engine) Serve

func (e *Engine) Serve() error

Serve starts gRPC and Gateway servers.

type GatewayServer

type GatewayServer struct {
	*Config
	// contains filtered or unexported fields
}

GatewayServer wraps gRPC gateway server setup process.

func (*GatewayServer) Serve

func (s *GatewayServer) Serve(l net.Listener, wg *sync.WaitGroup)

Serve implements Server.Shutdown

func (*GatewayServer) Shutdown

func (s *GatewayServer) Shutdown()

Shutdown implements Server.Shutdown

type GrpcServer

type GrpcServer struct {
	*Config
	// contains filtered or unexported fields
}

GrpcServer wraps grpc.Server setup process.

func (*GrpcServer) Serve

func (s *GrpcServer) Serve(l net.Listener, wg *sync.WaitGroup)

Serve implements Server.Shutdown

func (*GrpcServer) Shutdown

func (s *GrpcServer) Shutdown()

Shutdown implements Server.Shutdown

type HTTPServerMiddleware added in v0.1.3

type HTTPServerMiddleware func(http.Handler) http.Handler

HTTPServerMiddleware is an interface of http server middleware

type LogFields

type LogFields map[string]interface{}

LogFields represents logged fields.

type Logger

type Logger interface {
	Info(msg string, fields LogFields)
	Error(msg string, fields LogFields)
}

Logger is an interface for logging in a grapi server.

var (
	// DefaultLogger is a default logger implementation.
	DefaultLogger Logger = &defaultLogger{
		Logger: log.New(os.Stdout, "[grapi] ", log.LstdFlags),
	}
)

type PassedHeaderDeciderFunc added in v0.1.3

type PassedHeaderDeciderFunc func(string) bool

PassedHeaderDeciderFunc returns true if given header should be passed to gRPC server metadata.

type RegisterGatewayHandlerFunc

type RegisterGatewayHandlerFunc func(context.Context, *runtime.ServeMux, *grpc.ClientConn) error

RegisterGatewayHandlerFunc represents gRPC gateway's register handler functions.

type RegisterGrpcServerImplFunc

type RegisterGrpcServerImplFunc func(s *grpc.Server)

RegisterGrpcServerImplFunc should register gRPC service server implementations to *grpc.Server.

type Server

type Server interface {
	Serve(l net.Listener, wg *sync.WaitGroup)
	Shutdown()
}

Server provides an interface for starting and stopping the server.

func NewGatewayServer

func NewGatewayServer(c *Config) Server

NewGatewayServer creates GrpcServer instance.

func NewGrpcServer

func NewGrpcServer(c *Config) Server

NewGrpcServer creates GrpcServer instance.

Jump to

Keyboard shortcuts

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