Help us shape the future of Go! Take the 2026 Go Developer Survey

tools

package
v0.9.82 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BufferSize2048   = 2 << 10
	BufferSize4096   = 2 << 11
	BufferSize8192   = 2 << 12
	BufferSize16384  = 2 << 13
	BufferSize32768  = 2 << 14
	BufferSize65536  = 2 << 15
	BufferSize131072 = 2 << 16
)
View Source
const (
	PaginationDefaultLimit  = 10
	PaginationMaximumLimit  = 100
	PaginationMaximumOffset = math.MaxInt32
)

Pagination defaults and bounds apply to paginated API operations across the project.

View Source
const ValidateRulesTagName = "v"

Variables

View Source
var ErrInvalidPagination = errors.New("invalid pagination")

Functions

func GetRequestIDFromContext

func GetRequestIDFromContext(ctx context.Context) string

func LoadTLSConfig added in v0.9.79

func LoadTLSConfig(caFile, certFile, keyFile, serverName string) (*tls.Config, error)

LoadTLSConfig uses system trust by default and always verifies the server certificate.

func LogAttrsFromContext added in v0.9.79

func LogAttrsFromContext(ctx context.Context) []slog.Attr

LogAttrsFromContext returns a fresh slice of correlation and application fields.

func RateLimitTTL added in v0.9.79

func RateLimitTTL(interval time.Duration, burst int, ttl time.Duration) (time.Duration, error)

RateLimitTTL retains a bucket until it could have refilled completely.

func SetRequestIDToContext

func SetRequestIDToContext(ctx context.Context, requestID string) context.Context

func SlogContextWrapper

func SlogContextWrapper(h slog.Handler) slog.Handler

func TraceNoReturn

func TraceNoReturn(
	ctx context.Context,
	tracerName string,
	spanName string,
	fn func(context.Context),
)

func TraceReturnErr

func TraceReturnErr(
	ctx context.Context,
	tracerName string,
	spanName string,
	fn func(context.Context) error,
) error

func TraceReturnT

func TraceReturnT[T any](
	ctx context.Context,
	tracerName string,
	spanName string,
	fn func(context.Context) T,
) T

func TraceReturnTWithErr

func TraceReturnTWithErr[T any](
	ctx context.Context,
	tracerName string,
	spanName string,
	fn func(context.Context) (T, error),
) (T, error)

func ValidateStructCompact

func ValidateStructCompact(s interface{}) error

ValidateStructCompact calls ValidateStruct but returns single error instance

func ValidateTLSConfig added in v0.9.79

func ValidateTLSConfig(config *tls.Config) error

func WithLogAttrs added in v0.9.79

func WithLogAttrs(ctx context.Context, attrs ...slog.Attr) context.Context

WithLogAttrs adds fields to logs made with the returned context. A derived context replaces fields with the same key without modifying its parent.

Types

type ContextFieldsHandler

type ContextFieldsHandler struct {
	slog.Handler
}

ContextFieldsHandler is wrapper around slog handler which automatically adds predefined fields to logs taking values from context.

func (*ContextFieldsHandler) Handle

func (*ContextFieldsHandler) WithAttrs

func (h *ContextFieldsHandler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*ContextFieldsHandler) WithGroup

func (h *ContextFieldsHandler) WithGroup(name string) slog.Handler

type Pagination added in v0.9.81

type Pagination struct {
	Limit  int
	Offset int
}

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

func (*RateLimiter) Limit

func (m *RateLimiter) Limit(ctx context.Context, key string) (bool, error)

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

type TLSOptions struct {
	CAFile     string
	CertFile   string
	KeyFile    string
	ServerName string
}

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

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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