Documentation
¶
Index ¶
- Constants
- Variables
- func GetRequestIDFromContext(ctx context.Context) string
- func LoadTLSConfig(caFile, certFile, keyFile, serverName string) (*tls.Config, error)
- func LogAttrsFromContext(ctx context.Context) []slog.Attr
- func RateLimitTTL(interval time.Duration, burst int, ttl time.Duration) (time.Duration, error)
- func SetRequestIDToContext(ctx context.Context, requestID string) context.Context
- func SlogContextWrapper(h slog.Handler) slog.Handler
- func TraceNoReturn(ctx context.Context, tracerName string, spanName string, ...)
- func TraceReturnErr(ctx context.Context, tracerName string, spanName string, ...) error
- func TraceReturnT[T any](ctx context.Context, tracerName string, spanName string, ...) T
- func TraceReturnTWithErr[T any](ctx context.Context, tracerName string, spanName string, ...) (T, error)
- func ValidateStructCompact(s interface{}) error
- func ValidateTLSConfig(config *tls.Config) error
- func WithLogAttrs(ctx context.Context, attrs ...slog.Attr) context.Context
- type ContextFieldsHandler
- type Pagination
- type PriorityQueue
- type RateLimiter
- type RateLimiterOption
- type StartupRetryPolicy
- type TLSOptions
- type ValidationError
Constants ¶
const ( BufferSize2048 = 2 << 10 BufferSize4096 = 2 << 11 BufferSize8192 = 2 << 12 BufferSize16384 = 2 << 13 BufferSize32768 = 2 << 14 BufferSize65536 = 2 << 15 BufferSize131072 = 2 << 16 )
const ( PaginationDefaultLimit = 10 PaginationMaximumLimit = 100 PaginationMaximumOffset = math.MaxInt32 )
Pagination defaults and bounds apply to paginated API operations across the project.
const ValidateRulesTagName = "v"
Variables ¶
var ErrInvalidPagination = errors.New("invalid pagination")
Functions ¶
func GetRequestIDFromContext ¶
func LoadTLSConfig ¶ added in v0.9.79
LoadTLSConfig uses system trust by default and always verifies the server certificate.
func LogAttrsFromContext ¶ added in v0.9.79
LogAttrsFromContext returns a fresh slice of correlation and application fields.
func RateLimitTTL ¶ added in v0.9.79
RateLimitTTL retains a bucket until it could have refilled completely.
func SetRequestIDToContext ¶
func TraceNoReturn ¶
func TraceReturnErr ¶
func TraceReturnT ¶
func TraceReturnTWithErr ¶
func ValidateStructCompact ¶
func ValidateStructCompact(s interface{}) error
ValidateStructCompact calls ValidateStruct but returns single error instance
func ValidateTLSConfig ¶ added in v0.9.79
Types ¶
type ContextFieldsHandler ¶
ContextFieldsHandler is wrapper around slog handler which automatically adds predefined fields to logs taking values from context.
type Pagination ¶ added in v0.9.81
func NormalizePagination ¶ added in v0.9.81
func NormalizePagination(limit, offset int) (Pagination, error)
NormalizePagination applies the default limit for zero and rejects values outside the shared bounds. Adapters call it after decoding input and before invoking services.
type PriorityQueue ¶
type PriorityQueue[T any] struct { // contains filtered or unexported fields }
PriorityQueue is a simple priority queue implementation with FIFO per Priority.
func NewPriorityQueue ¶
func NewPriorityQueue[T any]() *PriorityQueue[T]
func (*PriorityQueue[T]) Dequeue ¶
func (pq *PriorityQueue[T]) Dequeue() (T, bool)
func (*PriorityQueue[T]) Enqueue ¶
func (pq *PriorityQueue[T]) Enqueue(priority int, value T)
func (*PriorityQueue[T]) Extract ¶
func (pq *PriorityQueue[T]) Extract() []T
func (*PriorityQueue[T]) IsEmpty ¶
func (pq *PriorityQueue[T]) IsEmpty() bool
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter applies a cache-backed rate limit to hashed, namespaced client keys.
func NewRateLimiter ¶
func NewRateLimiter( cache cacheAccessor, namespace string, rate int, burst int, ttl time.Duration, opts ...RateLimiterOption, ) *RateLimiter
type RateLimiterOption ¶ added in v0.9.79
type RateLimiterOption func(*RateLimiter)
func WithRateLimitWindow ¶ added in v0.9.79
func WithRateLimitWindow(window time.Duration) RateLimiterOption
WithRateLimitWindow sets the period over which the configured rate refills. The default window is one second.
type StartupRetryPolicy ¶ added in v0.9.81
type StartupRetryPolicy struct {
Timeout time.Duration
InitialBackoff time.Duration
MaxBackoff time.Duration
}
StartupRetryPolicy configures retries during dependency initialization.
func DefaultStartupRetryPolicy ¶ added in v0.9.81
func DefaultStartupRetryPolicy() StartupRetryPolicy
func (StartupRetryPolicy) Do ¶ added in v0.9.81
func (p StartupRetryPolicy) Do( ctx context.Context, backend string, logger *slog.Logger, connect func(context.Context) error, ) error
Do retries dependency initialization until the policy or parent context expires. Each attempt must honor the supplied context or bound its own I/O, and clean up failed connections and any connections acquired after cancellation.
type TLSOptions ¶ added in v0.9.79
func (TLSOptions) LoadConfig ¶ added in v0.9.79
func (o TLSOptions) LoadConfig(enabled bool) (*tls.Config, error)
LoadConfig loads client TLS settings. CAFile extends the system trust store.
func (TLSOptions) LoadServerConfig ¶ added in v0.9.79
func (o TLSOptions) LoadServerConfig(enabled bool) (*tls.Config, error)
LoadServerConfig requires a server certificate and key when TLS is enabled. Setting CAFile enables mutual TLS and trusts only clients signed by those CAs.
type ValidationError ¶
type ValidationError struct {
// contains filtered or unexported fields
}
func ValidateStruct ¶
func ValidateStruct(s interface{}) []ValidationError
ValidateStruct validates arbitrary struct
func (ValidationError) Code ¶
func (e ValidationError) Code() string
func (ValidationError) Detail ¶
func (e ValidationError) Detail() string
func (ValidationError) Pointer ¶
func (e ValidationError) Pointer() string