Documentation ¶
Overview ¶
Package utils provides a collection of helper functions for various tasks.
This package includes utilities for UUID generation, date formatting, image processing, URL query manipulation, random selection, color operations, and request ID colorization. It's designed to support common operations across different parts of the application.
Index ¶
- func BlurImage(imgBytes []byte) ([]byte, error)
- func ColorizeRequestId(requestID string) string
- func CombineQueries(urlQueries url.Values, refererURL string) (url.Values, error)
- func DateToLayout(input string) string
- func FileExists(filename string) bool
- func GenerateUUID() string
- func ImageToBase64(imgBtyes []byte) (string, error)
- func IsSleepTime(sleepStartTime, sleepEndTime string, currentTime time.Time) (bool, error)
- func RandomItem[T any](s []T) T
- type AssetWithWeighting
- type Color
- type WeightedAsset
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ColorizeRequestId ¶ added in v0.7.0
ColorizeRequestId takes a request ID string and returns a colorized string representation. It generates a color based on the input string, determines the best contrasting text color, and applies styling using lipgloss to create a visually distinct, colored representation of the request ID.
func CombineQueries ¶ added in v0.2.1
CombineQueries combine URL.Query() and Referer() queries NOTE: Referer queries will overwrite URL queries
func DateToLayout ¶ added in v0.6.0
DateToLayout takes a string and replaces normal date layouts to GO layouts
func FileExists ¶ added in v0.11.0
func ImageToBase64 ¶
ImageToBase64 converts image bytes into a base64 string
func IsSleepTime ¶ added in v0.11.0
func RandomItem ¶ added in v0.3.0
func RandomItem[T any](s []T) T
RandomItem returns a random item from given slice
Types ¶
type AssetWithWeighting ¶ added in v0.11.0
type AssetWithWeighting struct { Asset WeightedAsset Weight int }
type Color ¶ added in v0.7.0
func StringToColor ¶ added in v0.7.0
StringToColor takes any string and returns a Color struct. Identical strings should return identical values
type WeightedAsset ¶ added in v0.11.0
func PickRandomImageType ¶ added in v0.11.0
func PickRandomImageType(useWeighting bool, peopleAndAlbums []AssetWithWeighting) WeightedAsset
PickRandomImageType selects a random image type based on the given configuration and weightings. It returns a WeightedAsset representing the picked image type.
func WeightedRandomItem ¶ added in v0.10.0
func WeightedRandomItem(assets []AssetWithWeighting) WeightedAsset
WeightedRandomItem selects a random asset from the given slice of WeightedAsset(s) based on their logarithmic weights. It uses a weighted random selection algorithm.