server

package
v6.7.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultName server prefix name
	DefaultName = "server"
)

Variables

View Source
var (
	// ServerContextKey is a context key. It can be used in HTTP / GRPC
	// handlers with context.WithValue to access the server that
	// started the handler. The associated value will be of type *Server.
	ServerContextKey = &contextKey{"pluto-server"}
)

Functions

func FromContextAny

func FromContextAny(ctx context.Context, key string) interface{}

FromContextAny returns from context the interface value to which the key is associated.

func InterfaceStreamServerInterceptor

func InterfaceStreamServerInterceptor(name string, val interface{}) grpc.StreamServerInterceptor

InterfaceStreamServerInterceptor wraps any type to grpc stream server

func InterfaceUnaryServerInterceptor

func InterfaceUnaryServerInterceptor(name string, val interface{}) grpc.UnaryServerInterceptor

InterfaceUnaryServerInterceptor wraps any type to grpc unary server

func WithContextAny

func WithContextAny(ctx context.Context, key string, val interface{}) context.Context

WithContextAny returns a copy of parent ctx in which the value associated with key is val.

func WrapperStreamServer

func WrapperStreamServer(interceptors ...grpc.StreamServerInterceptor) grpc.StreamServerInterceptor

WrapperStreamServer creates a single interceptor out of a chain of many interceptors Execution is done in right-to-left order

func WrapperUnaryServer

func WrapperUnaryServer(interceptors ...grpc.UnaryServerInterceptor) grpc.UnaryServerInterceptor

WrapperUnaryServer creates a single interceptor out of a chain of many interceptors Execution is done in right-to-left order

Types

type Config

type Config struct {
	ID           string
	Name         string
	Description  string
	Addr         string // TCP address (e.g. localhost:8000) to listen on, ":http" if empty
	Format       string
	Mux          *router.Router
	TLSConfig    *tls.Config // optional TLS config, used by ListenAndServeTLS
	GRPCRegister GRPCRegisterServiceFunc
	Discovery    discovery.Discovery
	ReadTimeout  time.Duration
	WriteTimeout time.Duration

	Middlewares              []router.Middleware            // http middlewares
	UnaryServerInterceptors  []grpc.UnaryServerInterceptor  // gRPC interceptors
	StreamServerInterceptors []grpc.StreamServerInterceptor // gRPC interceptors
	// contains filtered or unexported fields
}

Config server configuaration options

func (*Config) Port

func (c *Config) Port() int

Port converts string Addr to int Port

type GRPCRegisterServiceFunc

type GRPCRegisterServiceFunc func(*grpc.Server)

GRPCRegisterServiceFunc grpc

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is used to set options for the server.

func Addr

func Addr(a string) Option

Addr server address

func Description

func Description(d string) Option

Description server description

func Discovery

func Discovery(d discovery.Discovery) Option

Discovery service discoery

func GRPCRegister

func GRPCRegister(fn GRPCRegisterServiceFunc) Option

GRPCRegister register client gRPC function

func ID

func ID(id string) Option

ID server id

func Logger

func Logger(l zerolog.Logger) Option

Logger sets a shallow copy from an input logger

func Middlewares

func Middlewares(m ...router.Middleware) Option

Middlewares slice with router.Middleware

func Mux

func Mux(m *router.Router) Option

Mux server multiplexer

func Name

func Name(n string) Option

Name server name

func ReadTimeout

func ReadTimeout(t time.Duration) Option

ReadTimeout is used by the http server to set a maximum duration before timing out read of the request. The default timeout is 10 seconds.

func StreamServerInterceptors

func StreamServerInterceptors(i ...grpc.StreamServerInterceptor) Option

StreamServerInterceptors slice with grpc.StreamServerInterceptor

func TLSConfig

func TLSConfig(certFile, keyFile string) Option

TLSConfig server multiplexer

func UnaryServerInterceptors

func UnaryServerInterceptors(i ...grpc.UnaryServerInterceptor) Option

UnaryServerInterceptors slice with grpc.UnaryServerInterceptor

func WriteTimeout

func WriteTimeout(t time.Duration) Option

WriteTimeout is used by the http server to set a maximum duration before timing out write of the response. The default timeout is 10 seconds.

type Server

type Server struct {
	// contains filtered or unexported fields
}

A Server defines parameters for running an HTTP server. The zero value for Server is a valid configuration.

func FromContext

func FromContext(ctx context.Context) *Server

FromContext returns server instance from a context

func New

func New(opts ...Option) *Server

New returns a new http server with cfg passed in

func (*Server) Health

func (s *Server) Health() *healthpb.HealthCheckResponse

func (*Server) Logger

func (s *Server) Logger() zerolog.Logger

Logger returns server logger

func (*Server) Name

func (s *Server) Name() string

Name returns server name

func (*Server) Run

func (s *Server) Run(opts ...Option) error

Run Server

func (*Server) Stop

func (s *Server) Stop()

Stop stops server by sending a message to close the listener via channel

func (*Server) WithContext

func (s *Server) WithContext(ctx context.Context) context.Context

WithContext returns a copy of ctx with server associated.

func (*Server) WithOptions

func (s *Server) WithOptions(opts ...Option) *Server

WithOptions clones the current Client, applies the supplied Options, and returns the resulting Client. It's safe to use concurrently.

type ServerStreamWithContext

type ServerStreamWithContext struct {
	// contains filtered or unexported fields
}

https://groups.google.com/forum/#!topic/grpc-io/Q88GQFTPF1o

func WrapServerStreamWithContext

func WrapServerStreamWithContext(stream grpc.ServerStream) *ServerStreamWithContext

WrapServerStreamWrapper returns a ServerStream that has the ability to overwrite context.

func (*ServerStreamWithContext) Context

Stream interface

func (*ServerStreamWithContext) RecvMsg

func (w *ServerStreamWithContext) RecvMsg(msg interface{}) error

func (*ServerStreamWithContext) SendHeader

func (w *ServerStreamWithContext) SendHeader(md metadata.MD) error

ServerStream interface

func (*ServerStreamWithContext) SendMsg

func (w *ServerStreamWithContext) SendMsg(msg interface{}) error

func (*ServerStreamWithContext) SetContext

func (w *ServerStreamWithContext) SetContext(ctx context.Context)

func (*ServerStreamWithContext) SetHeader

func (w *ServerStreamWithContext) SetHeader(md metadata.MD) error

func (*ServerStreamWithContext) SetTrailer

func (w *ServerStreamWithContext) SetTrailer(md metadata.MD)

type TCPKeepAliveListener

type TCPKeepAliveListener struct {
	*net.TCPListener
}

TCPKeepAliveListener is a copy of tcpKeepAliveListener source: net/http/server.go

tcpKeepAliveListener sets TCP keep-alive timeouts on accepted connections. It's used by ListenAndServe and ListenAndServeTLS so dead TCP connections (e.g. closing laptop mid-download) eventually go away.

func (TCPKeepAliveListener) Accept

func (ln TCPKeepAliveListener) Accept() (c net.Conn, err error)

Accept implements the Accept method in the Listener interface; it waits for the next call and returns a generic Conn.

Directories

Path Synopsis
Package router trie based on a 256-way trie expressed on the textbook Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne A string symbol table for extended ASCII strings, implemented using a 256-way trie.
Package router trie based on a 256-way trie expressed on the textbook Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne A string symbol table for extended ASCII strings, implemented using a 256-way trie.

Jump to

Keyboard shortcuts

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