util

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertQueryParams

func ConvertQueryParams(params QueryParams) (filter bson.D, sort bson.D, projection bson.D)

func GetEnv added in v0.3.0

func GetEnv(name, fallback string) string

GetEnv returns the value of the named environment variable, or fallback when it is unset or empty.

func GetEnvInt added in v0.3.0

func GetEnvInt(name string, fallback int) int

GetEnvInt returns the named environment variable parsed as an int, or fallback when it is unset, empty, or not a valid integer.

func RedisPool added in v0.3.0

func RedisPool() *redis.Pool

RedisPool builds a redigo connection pool from REDIS_HOST / REDIS_PORT / REDIS_PASS, for use as the backing store of the shared per-client rate limiter (and any other Redis need a service has). It returns nil when REDIS_HOST is unset, so a service with no Redis configured runs without the dependency - callers that require Redis (e.g. ratelimit.Middleware) must treat a nil pool as a fatal misconfiguration, per the fail-closed contract.

Types

type Filter

type Filter struct {
	Field     string
	Operation *string
	Value     []string
}

type Projection

type Projection struct {
	Field     string
	Inclusion bool
}

type QueryParams

type QueryParams struct {
	Start      int64
	Limit      int
	Sort       []Sort
	Filter     []Filter
	Projection []Projection
}

func GetQueryParams

func GetQueryParams(query string) (QueryParams, error)

GetQueryParams parses a raw querystring into paging/sort/filter/projection parameters. It returns an error for a filter that names an operator outside filterOperators, so a list handler can answer 400 instead of silently ignoring or mishandling the filter.

type Sort

type Sort struct {
	Field string
	Order int
}

Jump to

Keyboard shortcuts

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