utils

package
v0.0.0-...-bbaddd9 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 27 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectMIMEType

func DetectMIMEType(data *([]byte)) string

func GenerateLockKey

func GenerateLockKey(identifier string) int64

func GetEnv

func GetEnv(key, fallback string) string

func GetExtFromFilename

func GetExtFromFilename(filename string) string

func GetExtFromMIMEType

func GetExtFromMIMEType(mimeType string) string

func GetImageDimensions

func GetImageDimensions(imageBytes []byte) (int32, int32, error)

func GetMimeTypeFromFilename

func GetMimeTypeFromFilename(filename string) string

func IsStrTruthy

func IsStrTruthy(s string) bool

func JsonEscape

func JsonEscape(i string) string

func MaybeRemoveExif

func MaybeRemoveExif(data []byte) ([]byte, error)

func Reversed

func Reversed[T any](s []T) []T

func RunWithLock

func RunWithLock(lock MutexLock, fn func() error) error

func RunWorkerPool

func RunWorkerPool[T any](tasks []WorkerTask[T], maxWorkers int) chan workerResult[T]

func RunWorkerPoolIter

func RunWorkerPoolIter[T any](seq iter.Seq2[T, error], execute func(T) error, maxWorkers int) chan workerResult[T]

RunWorkerPoolIter is like RunWorkerPool but feeds jobs from an iter.Seq2 instead of a pre-built slice. The jobs channel is bounded to maxWorkers*2 so at most that many items are held in memory at once beyond what workers are actively processing. The iterator is drained in a separate goroutine; if it yields an error the error is forwarded as a result and iteration stops.

func SafeDeref

func SafeDeref[T any](p *T) T

func SafeDerefWithDefault

func SafeDerefWithDefault[T any](p *T, defaultValue T) T

func Slugify

func Slugify(s string, lower ...bool) string

Types

type Lazy

type Lazy[T any] struct {
	New func() T
	// contains filtered or unexported fields
}

func NewLazy

func NewLazy[T any](newfunc func() T) *Lazy[T]

func (*Lazy[T]) Value

func (this *Lazy[T]) Value() T

type MutexLock

type MutexLock interface {
	AcquireLock() (bool, error)
	ReleaseLock() error
}

type PgAdvisoryLock

type PgAdvisoryLock struct {
	// contains filtered or unexported fields
}

func NewPgAdvisoryLock

func NewPgAdvisoryLock(db *sql.DB, lockKey int64) *PgAdvisoryLock

func (*PgAdvisoryLock) AcquireLock

func (p *PgAdvisoryLock) AcquireLock() (bool, error)

func (*PgAdvisoryLock) ReleaseLock

func (p *PgAdvisoryLock) ReleaseLock() error

type RedisLock

type RedisLock struct {
	// contains filtered or unexported fields
}

func NewRedisLock

func NewRedisLock(client *redis.Client, key string, ttl time.Duration) *RedisLock

func (*RedisLock) AcquireLock

func (r *RedisLock) AcquireLock() (bool, error)

func (*RedisLock) ReleaseLock

func (r *RedisLock) ReleaseLock() error

type SeekerReader

type SeekerReader interface {
	io.Seeker
	io.Reader
}

type WorkerTask

type WorkerTask[T any] struct {
	Job     T
	Execute func(T) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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