utils

package
v0.11.3 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2024 License: AGPL-3.0 Imports: 23 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlurImage

func BlurImage(imgBytes []byte) ([]byte, error)

BlurImage converts image bytes into a blurred base64 string

func ColorizeRequestId added in v0.7.0

func ColorizeRequestId(requestID string) string

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

func CombineQueries(urlQueries url.Values, refererURL string) (url.Values, error)

CombineQueries combine URL.Query() and Referer() queries NOTE: Referer queries will overwrite URL queries

func DateToLayout added in v0.6.0

func DateToLayout(input string) string

DateToLayout takes a string and replaces normal date layouts to GO layouts

func FileExists added in v0.11.0

func FileExists(filename string) bool

func GenerateUUID added in v0.9.0

func GenerateUUID() string

GenerateUUID generates as UUID

func ImageToBase64

func ImageToBase64(imgBtyes []byte) (string, error)

ImageToBase64 converts image bytes into a base64 string

func IsSleepTime added in v0.11.0

func IsSleepTime(sleepStartTime, sleepEndTime string, currentTime time.Time) (bool, error)

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

type Color struct {
	R   int
	G   int
	B   int
	RGB string
	Hex string
}

func StringToColor added in v0.7.0

func StringToColor(inputString string) Color

StringToColor takes any string and returns a Color struct. Identical strings should return identical values

type WeightedAsset added in v0.11.0

type WeightedAsset struct {
	Type string
	ID   string
}

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.

Jump to

Keyboard shortcuts

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