Versions in this module Expand all Collapse all v2 v2.7.1 Nov 12, 2023 Changes in this version + var ErrLimitReached = errors.New("limit reached") + var ErrTooLargeJSON = errors.New("too large JSON") + var ErrUnmarshalJSON = errors.New("unmarshalling JSON failed") + func BasicAuth(user, pass string) string + func BearerAuth(token string) string + func ContainsAll[T comparable](haystack []T, needles []T) bool + func ContainsIP(haystack []netip.Prefix, needle netip.Addr) bool + func Contains[T comparable](haystack []T, needle T) bool + func DetectContentType(b []byte, filename string) (mimeType string, ext string) + func FileExists(filename string) bool + func FormatSize(b int64) string + func FormatTime(t time.Time) string + func Gzip(next http.Handler) http.Handler + func Int(v int) *int + func LastString(s []string, def string) string + func Max[T int | int64 | rate.Limit](a, b T) T + func MaybeMarshalJSON(v any) string + func MinMax[T int | int64](value, min, max T) T + func NextOccurrenceUTC(timeOfDay, base time.Time) time.Time + func ParseDuration(s string) (time.Duration, error) + func ParseFutureTime(s string, now time.Time) (time.Time, error) + func ParsePriority(priority string) (int, error) + func ParseSize(s string) (int64, error) + func PriorityString(priority int) (string, error) + func QuoteCommand(command []string) string + func RandomLowerStringPrefix(prefix string, length int) string + func RandomString(length int) string + func RandomStringPrefix(prefix string, length int) string + func ReadPassword(in io.Reader) ([]byte, error) + func Retry[T any](f func() (*T, error), after ...time.Duration) (t *T, err error) + func ShortTopicURL(s string) string + func SplitKV(s string, sep string) (key string, value string) + func SplitNoEmpty(s string, sep string) []string + func String(v string) *string + func Time(v time.Time) *time.Time + func UnmarshalJSONWithLimit[T any](r io.ReadCloser, limit int, allowEmpty bool) (*T, error) + func UnmarshalJSON[T any](body io.ReadCloser) (*T, error) + func ValidRandomString(s string, length int) bool + type BatchingQueue struct + func NewBatchingQueue[T any](batchSize int, timeout time.Duration) *BatchingQueue[T] + func (q *BatchingQueue[T]) Dequeue() <-chan []T + func (q *BatchingQueue[T]) Enqueue(element T) + type CachingEmbedFS struct + FS embed.FS + ModTime time.Time + func (f CachingEmbedFS) Open(name string) (fs.File, error) + type ContentTypeWriter struct + func NewContentTypeWriter(w http.ResponseWriter, filename string) *ContentTypeWriter + func (w *ContentTypeWriter) Write(p []byte) (n int, err error) + type FixedLimiter struct + func NewFixedLimiter(limit int64) *FixedLimiter + func NewFixedLimiterWithValue(limit, value int64) *FixedLimiter + func (l *FixedLimiter) Allow() bool + func (l *FixedLimiter) AllowN(n int64) bool + func (l *FixedLimiter) Reset() + func (l *FixedLimiter) Value() int64 + type LimitWriter struct + func NewLimitWriter(w io.Writer, limiters ...Limiter) *LimitWriter + func (w *LimitWriter) Write(p []byte) (n int, err error) + type Limiter interface + Allow func() bool + AllowN func(n int64) bool + Reset func() + Value func() int64 + type LookupCache struct + func NewLookupCache[T any](lookup LookupFunc[T], ttl time.Duration) *LookupCache[T] + func (c *LookupCache[T]) Value() (T, error) + type LookupFunc func() (T, error) + type PeekedReadCloser struct + LimitReached bool + PeekedBytes []byte + func Peek(underlying io.ReadCloser, limit int) (*PeekedReadCloser, error) + func (r *PeekedReadCloser) Close() error + func (r *PeekedReadCloser) Read(p []byte) (n int, err error) + type RateLimiter struct + func NewBytesLimiter(bytes int, interval time.Duration) *RateLimiter + func NewRateLimiter(r rate.Limit, b int) *RateLimiter + func NewRateLimiterWithValue(r rate.Limit, b int, value int64) *RateLimiter + func (l *RateLimiter) Allow() bool + func (l *RateLimiter) AllowN(n int64) bool + func (l *RateLimiter) Reset() + func (l *RateLimiter) Value() int64