server

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateGRPCServer

func CreateGRPCServer(ctx context.Context, registerServices func(*grpc.Server), configs Configs, serverOptions ...grpc.ServerOption) func()

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 GatewayErrorHandler(
	ctx context.Context,
	mux *runtime.ServeMux,
	marshaler runtime.Marshaler,
	writer http.ResponseWriter,
	request *http.Request,
	err error,
)

func IncomingHeaderMatcher

func IncomingHeaderMatcher(header string) (string, bool)

func LoggerChiContextMiddleware

func LoggerChiContextMiddleware() func(http.Handler) http.Handler

func LoggerContextMiddleware

func LoggerContextMiddleware() mux.MiddlewareFunc

func LoggingChiMiddleware

func LoggingChiMiddleware(next http.Handler) http.Handler

LoggingChiMiddleware логирует запрос, добавляет X-Correlation-ID.

func LoggingMiddleware

func LoggingMiddleware(next http.Handler) http.Handler

func PanicHandler

func PanicHandler(ctx context.Context, p interface{}) error

func RecoverChiMiddleware

func RecoverChiMiddleware(next http.Handler) http.Handler

RecoverChiMiddleware ловит panic внутри хэндлеров.

func RecoverMiddleware

func RecoverMiddleware(next http.Handler) http.Handler

func RequestTimeout

func RequestTimeout(d time.Duration) func(http.Handler) http.Handler

func TimeoutUnaryInterceptor

func TimeoutUnaryInterceptor(timeout time.Duration) grpc.UnaryServerInterceptor

Types

type Configs

type Configs struct {
	Port       string
	Network    string
	Reflection bool
}

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 GatewayRegisterFunc func(
	ctx context.Context,
	mux *runtime.ServeMux,
	endpoint string,
	opts []grpc.DialOption,
) error

type HTTPServer

type HTTPServer struct {
	Router *mux.Router
	// contains filtered or unexported fields
}

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

type HTTPServerChi struct {
	Router *chi.Mux
	// contains filtered or unexported fields
}

func (*HTTPServerChi) ApplyServerOptions

func (s *HTTPServerChi) ApplyServerOptions(opts ...Option)

ApplyServerOptions — точка конфигурации http.Server из кода маршрутов.

type Handlers

type Handlers struct {
}

type Option

type Option func(*http.Server)

func WithBaseContext

func WithBaseContext(fn func(net.Listener) context.Context) Option

func WithConnContext

func WithConnContext(fn func(ctx context.Context, c net.Conn) context.Context) Option

func WithDisableKeepAlives

func WithDisableKeepAlives(disable bool) Option

func WithErrorLog

func WithErrorLog(l *log.Logger) Option

func WithIdleTimeout

func WithIdleTimeout(d time.Duration) Option

func WithMaxHeaderBytes

func WithMaxHeaderBytes(n int) Option

func WithReadHeaderTimeout

func WithReadHeaderTimeout(d time.Duration) Option

func WithReadTimeout

func WithReadTimeout(d time.Duration) Option

func WithTLSConfig

func WithTLSConfig(cfg *tls.Config) Option

func WithWriteTimeout

func WithWriteTimeout(d time.Duration) Option

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

type RegisterGatewayFunc

type RegisterGatewayFunc func(
	ctx context.Context,
	mux *runtime.ServeMux,
	endpoint string,
	opts []grpc.DialOption,
) error

type SwaggerConfig

type SwaggerConfig struct {
	Enabled bool

	// URL Swagger UI.
	UIPath string

	// URL, по которому клиент получит JSON-спецификацию.
	JSONPath string

	// Файл на диске.
	JSONFile string
}

type ZeroPool

type ZeroPool struct{}

func (ZeroPool) Get

func (ZeroPool) Get(n int) *[]byte

func (ZeroPool) Put

func (ZeroPool) Put(*[]byte)

Jump to

Keyboard shortcuts

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