server

package
v0.0.0-...-5783bb9 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package server provides common extensions (middleware) required for production DRPC servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoggingHook

type LoggingHook func(fields *metadata.MD, stream drpc.Stream)

LoggingHook provides a mechanism to extend a message fields just before is submitted.

type Middleware

type Middleware func(drpc.Handler) drpc.Handler

Middleware elements allow to customize the internal requests processing by the server.

func AuthByToken

func AuthByToken(key string, validator TokenValidator) Middleware

AuthByToken allows to use an external authentication mechanism using bearer tokens as credentials. The token must be present in the request's metadata under `key` and be valid according to the provided `validator`.

func Logging

func Logging(logger xlog.Logger, hook LoggingHook) Middleware

Logging produce output for the processed RPC requests tagged with standard ECS details by default. Fields can be extended by providing a hook function.

func PanicRecovery

func PanicRecovery() Middleware

PanicRecovery allows the server to convert unhandled panic events into an "internal" RPC error. This will prevent the server from crashing if a handler produces a `panic` operation.

func RateLimit

func RateLimit(limit int) Middleware

RateLimit enforce a maximum limit of RPC requests per-second on the server. It is implemented as a `token bucket` instance. More information: https://en.wikipedia.org/wiki/Token_bucket

type TokenValidator

type TokenValidator func(token string) bool

TokenValidator represents an external authentication mechanism used to validate bearer credentials. In case of any error the validation function must return 'false' and the server will return an 'invalid credentials' error message.

Jump to

Keyboard shortcuts

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