middleware

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: Unlicense Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const LoggerKey ctxKeyLogger = 76

RequestIDKey is the key that holds the unique request ID in a request context.

View Source
const RequestIDKey ctxKeyRequestID = 0

RequestIDKey is the key that holds the unique request ID in a request context.

Variables

View Source
var IsTTY bool
View Source
var LegacyUnderscoreReplacer = MethodReplacer(strings.NewReplacer("_", "/"))
View Source
var RequestIDHeader = "X-Request-Id"

RequestIDHeader is the name of the jrpc Header which contains the request id. Exported so that it can be changed by developers

Functions

func GetLogger

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

func GetReqID

func GetReqID(ctx context.Context) string

GetReqID returns a request ID from the given context if one is present. Returns the empty string if a request ID cannot be found.

func Logger

func Logger(next jsonrpc.Handler) jsonrpc.Handler

func MethodReplacer

func MethodReplacer(replacer *strings.Replacer) jsonrpc.Middleware

MethodReplacer will use the replacer on every method before handling

func New

func New(h jsonrpc.Handler) func(next jsonrpc.Handler) jsonrpc.Handler

New will create a new middleware handler from a jrpc.Handler.

func NewLogger added in v0.2.16

func NewLogger(logger *slog.Logger) func(next jsonrpc.Handler) jsonrpc.Handler

func NextRequestID

func NextRequestID() uint64

NextRequestID generates the next request ID in the sequence.

func PrintPrettyStack

func PrintPrettyStack(rvr interface{})

func Recoverer

func Recoverer(next jsonrpc.Handler) jsonrpc.Handler

Recoverer is a middleware that recovers from panics, logs the panic (and a backtrace), and returns a jrpc 500 (Internal Server Error) status if possible. Recoverer prints a request ID if one is provided.

Alternatively, look at jrpcs://github.com/go-chi/jrpclog middleware pkgs.

func RequestID

func RequestID(next jsonrpc.Handler) jsonrpc.Handler

RequestID is a middleware that injects a request ID into the context of each request. A request ID is a string of the form "host.example.com/random-0001", where "random" is a base62 random string that uniquely identifies this go process, and where the last number is an atomically incremented request counter.

Types

This section is empty.

Jump to

Keyboard shortcuts

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