Documentation
¶
Index ¶
- func CreateGRPCServer(ctx context.Context, registerServices func(*grpc.Server), configs Configs, ...) func()
- func CreateHTTPChiServer(routes func(*HTTPServerChi), port string, preShutdownState *PreShutdownState, ...) func()
- func CreateHttpServer(router func(simple *HTTPServer), port string, mwf ...mux.MiddlewareFunc) func()
- func DrainMiddleware(state *PreShutdownState, responseCallback func(w http.ResponseWriter)) func(http.Handler) http.Handler
- func EnforceMaxSendSize(max int) grpc.UnaryServerInterceptor
- func GatewayErrorHandler(ctx context.Context, mux *runtime.ServeMux, marshaler runtime.Marshaler, ...)
- func IncomingHeaderMatcher(header string) (string, bool)
- func LoggerChiContextMiddleware() func(http.Handler) http.Handler
- func LoggerContextMiddleware() mux.MiddlewareFunc
- func LoggingChiMiddleware(next http.Handler) http.Handler
- func LoggingMiddleware(next http.Handler) http.Handler
- func PanicHandler(ctx context.Context, p interface{}) error
- func RecoverChiMiddleware(next http.Handler) http.Handler
- func RecoverMiddleware(next http.Handler) http.Handler
- func RequestTimeout(d time.Duration) func(http.Handler) http.Handler
- func TimeoutUnaryInterceptor(timeout time.Duration) grpc.UnaryServerInterceptor
- type Configs
- type GRPCGatewayConfigs
- type GRPCGatewayServer
- type GRPCServer
- type GatewayRegisterFunc
- type HTTPServer
- type HTTPServerChi
- type Handlers
- type Option
- func WithBaseContext(fn func(net.Listener) context.Context) Option
- func WithConnContext(fn func(ctx context.Context, c net.Conn) context.Context) Option
- func WithDisableKeepAlives(disable bool) Option
- func WithErrorLog(l *log.Logger) Option
- func WithIdleTimeout(d time.Duration) Option
- func WithMaxHeaderBytes(n int) Option
- func WithReadHeaderTimeout(d time.Duration) Option
- func WithReadTimeout(d time.Duration) Option
- func WithTLSConfig(cfg *tls.Config) Option
- func WithWriteTimeout(d time.Duration) Option
- type PreShutdownState
- type RegisterGatewayFunc
- type SwaggerConfig
- type ZeroPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateGRPCServer ¶
func CreateHTTPChiServer ¶
func CreateHTTPChiServer( routes func(*HTTPServerChi), port string, preShutdownState *PreShutdownState, mwf ...func(http.Handler) http.Handler, ) func()
CreateHTTPChiServer создаёт и запускает HTTP-сервер на chi. Сигнатуры не меняем: маршруты, порт, middleware-список. Конфигурацию http.Server можно задать внутри `routes` через s.ApplyServerOptions(...).
func CreateHttpServer ¶
func CreateHttpServer(router func(simple *HTTPServer), port string, mwf ...mux.MiddlewareFunc) func()
func DrainMiddleware ¶
func DrainMiddleware( state *PreShutdownState, responseCallback func(w http.ResponseWriter), ) func(http.Handler) http.Handler
func EnforceMaxSendSize ¶
func EnforceMaxSendSize(max int) grpc.UnaryServerInterceptor
EnforceMaxSendSize это костыль, который позволяет ограничить размер ответа сервера, чтобы сервер не протекал по памяти. если его убрать, то когда ответ превышает лимит, то сервер начинает течь по памяти, и в итоге падает. Днище, но нечего поделать. max передавать желательно меньше чем сервер может вернуть ответом. Я обычно передают 0.9*out_grpc_body_size Управлять только снаружи. Вызвать в цепочке только первым. Тронешь - убьет!
func GatewayErrorHandler ¶
func IncomingHeaderMatcher ¶
func LoggerContextMiddleware ¶
func LoggerContextMiddleware() mux.MiddlewareFunc
func LoggingChiMiddleware ¶
LoggingChiMiddleware логирует запрос, добавляет X-Correlation-ID.
func PanicHandler ¶
func RecoverChiMiddleware ¶
RecoverChiMiddleware ловит panic внутри хэндлеров.
func TimeoutUnaryInterceptor ¶
func TimeoutUnaryInterceptor(timeout time.Duration) grpc.UnaryServerInterceptor
Types ¶
type GRPCGatewayConfigs ¶
type GRPCGatewayConfigs struct {
// Адрес HTTP grpc-gateway, например ":9099".
HTTPAddr string
// Адрес настоящего gRPC-сервера, например "127.0.0.1:9009".
GRPCEndpoint string
// Обычно "tcp".
Network string
ReadHeaderTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
ShutdownTimeout time.Duration
MaxHeaderBytes int
Swagger SwaggerConfig
}
type GRPCGatewayServer ¶
type GRPCGatewayServer struct {
// contains filtered or unexported fields
}
func NewGRPCGatewayServer ¶
func NewGRPCGatewayServer( configs GRPCGatewayConfigs, ) (*GRPCGatewayServer, error)
func (*GRPCGatewayServer) Start ¶
func (s *GRPCGatewayServer) Start( ctx context.Context, registerFunc GatewayRegisterFunc, dialOptions []grpc.DialOption, muxOptions []runtime.ServeMuxOption, ) (func(), error)
type GRPCServer ¶
type GRPCServer struct {
// contains filtered or unexported fields
}
func (*GRPCServer) Start ¶
func (s *GRPCServer) Start(ctx context.Context, registerServices func(*grpc.Server), serverOptions ...grpc.ServerOption) func()
type GatewayRegisterFunc ¶
type HTTPServer ¶
func (*HTTPServer) RunHTTPServer ¶
func (simple *HTTPServer) RunHTTPServer(balancer http.Handler, mwf ...mux.MiddlewareFunc) func()
func (*HTTPServer) ToConfigureHandlers ¶
func (simple *HTTPServer) ToConfigureHandlers(configure func(simple *HTTPServer)) *HTTPServer
type HTTPServerChi ¶
func (*HTTPServerChi) ApplyServerOptions ¶
func (s *HTTPServerChi) ApplyServerOptions(opts ...Option)
ApplyServerOptions — точка конфигурации http.Server из кода маршрутов.
type Option ¶
func WithConnContext ¶
func WithDisableKeepAlives ¶
func WithErrorLog ¶
func WithIdleTimeout ¶
func WithMaxHeaderBytes ¶
func WithReadHeaderTimeout ¶
func WithReadTimeout ¶
func WithTLSConfig ¶
func WithWriteTimeout ¶
type PreShutdownState ¶
type PreShutdownState struct {
State atomic.Value
Need bool
TimeForDraining time.Duration
TimeForShutdown time.Duration
}
func NewPreShutdownState ¶
func NewPreShutdownState(need bool, timeForDraining, timeForShutdown time.Duration) *PreShutdownState