middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextKeyUstreamProvider  = contextKey("UpstreamProvider")
	ContextKeyUstreamAddr      = contextKey("UpstreamAddr")
	LogFieldsCtxKey            = contextKey("LogFields")
	LogWithParamsCtxKey        = contextKey("LogWithParams")
	LogWithIgnoreMethodsCtxKey = contextKey("LogWithIgnoreMethods")
	LogRequestStartTime        = contextKey("LogRequestStartTime")
	LogLoggerCtxKey            = contextKey("LogLogger")

	RPCPayloadCtxKey             = contextKey("RPCPayload")
	RPCMethodCtxKey              = contextKey("RPCMethod")
	RPCRequestID                 = contextKey("RPCRequestID")
	RPCMiddlewareCtxKey          = contextKey("RPCMiddleware")
	ConnectionTypeCtxKey         = contextKey("ConnectionType")
	ConnectionParentCtxKey       = contextKey("ConnectionParentContext")
	ConnectionClientWSCtxKey     = contextKey("ConnectionClientWS")
	ConnectionClientIDCtxKey     = contextKey("ConnectionClientID")
	ConnectionClientCancelCtxKey = contextKey("ConnectionClientCancel")
)
View Source
const (
	ConnectionTypeWebsocketCtx = "websocket"
	ConnectionTypeHTTPCtx      = "http"
	RPCPayloadTypeBatchCtx     = "batch"
	RPCPayloadTypeFrameCtx     = "frame"
)

Variables

This section is empty.

Functions

func AcceptConnection added in v0.0.4

func AcceptConnection(next http.Handler) http.Handler

func AddLogField

func AddLogField(ctx context.Context, k string, v string)

func CancelConnection added in v0.0.4

func CancelConnection(ctx context.Context, err error)

func CopyHeader

func CopyHeader(dst, src http.Header)

func DenyRPCMethods

func DenyRPCMethods(methods []string) func(http.Handler) http.Handler

func EndpointProvider

func EndpointProvider(prov endpoint.Provider) func(http.Handler) http.Handler

func GetAssignedUpstream

func GetAssignedUpstream(ctx context.Context) string

func GetClientConnection added in v0.1.0

func GetClientConnection(ctx context.Context) *websocket.Conn

func GetClientConnectionContext added in v0.1.0

func GetClientConnectionContext(ctx context.Context) context.Context

func GetClientConnectionType

func GetClientConnectionType(ctx context.Context) string

func GetConnectionID

func GetConnectionID(ctx context.Context) string

func GetEndpointProvider

func GetEndpointProvider(ctx context.Context) endpoint.Provider

func GetJsonRPCFrame

func GetJsonRPCFrame(ctx context.Context) *dto.RPCFrame

func GetLogField

func GetLogField(ctx context.Context, k string) string

func GetLogger

func GetLogger(ctx context.Context) *logrus.Logger

func GetRPCMethod

func GetRPCMethod(ctx context.Context) string

func GetRPCRequestID

func GetRPCRequestID(ctx context.Context) int

func IsWebsocket

func IsWebsocket(r *http.Request) bool

func JsonRPC

func JsonRPC(opts ...JsonRPCMiddlewareOption) func(http.Handler) http.Handler

func LogRequestDetails

func LogRequestDetails(r *http.Request)

func LogSubscriptionDetails

func LogSubscriptionDetails(ctx context.Context, client string, upstream string, f dto.RPCFrame)

func Logger added in v0.0.4

func Logger(l *logrus.Logger, opts ...LoggerOption) func(http.Handler) http.Handler

func ThrottleWithOpts

func ThrottleWithOpts(opts ThrottleOpts) func(http.Handler) http.Handler

func WithContextValue

func WithContextValue(r *http.Request, key any, v any) *http.Request

func WithNewBody

func WithNewBody(r *http.Request, b []byte) *http.Request

Types

type ErrorResponse

type ErrorResponse struct {
	Err            error  `json:"-"`
	HTTPStatusCode int    `json:"-"`
	StatusText     string `json:"status"`
	ErrorText      string `json:"error,omitempty"`
}

func ErrorBadGateway

func ErrorBadGateway(err error) *ErrorResponse

func ErrorInternalServer

func ErrorInternalServer(err error) *ErrorResponse

func ErrorInvalidRequest

func ErrorInvalidRequest(err error) *ErrorResponse

func (*ErrorResponse) Render

type HttpMetrics

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

func (*HttpMetrics) GetMonitoringEventTypes

func (m *HttpMetrics) GetMonitoringEventTypes() []string

func (*HttpMetrics) Middleware

func (m *HttpMetrics) Middleware() func(http.Handler) http.Handler

func (*HttpMetrics) SetObserver

func (m *HttpMetrics) SetObserver(mon monitoring.Observer)

type InMemoryWriter

type InMemoryWriter struct {
	Buf    []byte
	Status int
	// contains filtered or unexported fields
}

func NewInMemoryWriter

func NewInMemoryWriter(w http.ResponseWriter) *InMemoryWriter

func (*InMemoryWriter) Header

func (w *InMemoryWriter) Header() http.Header

func (*InMemoryWriter) Write

func (w *InMemoryWriter) Write(b []byte) (int, error)

func (*InMemoryWriter) WriteHeader

func (w *InMemoryWriter) WriteHeader(statusCode int)

type JsonRPCMiddleware

type JsonRPCMiddleware struct {
}

func GetJsonRPCMiddleware

func GetJsonRPCMiddleware(ctx context.Context) *JsonRPCMiddleware

func (*JsonRPCMiddleware) NewFrameContext

func (m *JsonRPCMiddleware) NewFrameContext(ctx context.Context, f *dto.RPCFrame) context.Context

func (*JsonRPCMiddleware) ParsePayload

func (m *JsonRPCMiddleware) ParsePayload(payload []byte) interface{}

type JsonRPCMiddlewareOption added in v0.0.4

type JsonRPCMiddlewareOption func(http.Handler) http.Handler

type LoggerOption added in v0.1.0

type LoggerOption func(context.Context) context.Context

func LogWithIgnoreMethods added in v0.1.0

func LogWithIgnoreMethods(methods []string) LoggerOption

func LogWithParams added in v0.1.0

func LogWithParams() LoggerOption

type RPCMiddleware

type RPCMiddleware interface {
	ParsePayload(payload []byte) interface{}
}

type ThrottleOpts

type ThrottleOpts struct {
	Limit          int
	BacklogLimit   int
	Context        context.Context
	BacklogTimeout time.Duration
	Observer       monitoring.Observer
}

ThrottleOpts represents a set of throttling options.

type WrapedWSWriter

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

func (*WrapedWSWriter) Header

func (w *WrapedWSWriter) Header() http.Header

func (*WrapedWSWriter) Write

func (w *WrapedWSWriter) Write(b []byte) (int, error)

func (*WrapedWSWriter) WriteHeader

func (w *WrapedWSWriter) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

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