grapiserver

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2018 License: MIT Imports: 15 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
	SetLogger(l Logger) Builder
	SetHTTPHeaderMapping(deciderFunc func(string) bool, mappingFunc func(string) string) 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
	HTTPHeaderMappingConfig         *HTTPHeaderMappingConfig
}

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 HTTPHeaderMappingConfig

type HTTPHeaderMappingConfig struct {
	DeciderFunc func(string) bool
	MapperFunc  func(string) string
}

HTTPHeaderMappingConfig contains functions for deciding and mapping http header keys.

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 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