utils

package
v0.0.0-...-9c662ae Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: AGPL-3.0 Imports: 18 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

Overview

Package utils includes all utility methods.

Index

Constants

View Source
const NoExpiration time.Duration = -1

NoExpiration requests a cache that never expires.

Variables

This section is empty.

Functions

func ChunkArray

func ChunkArray[T any](arr []T, chunkSize int) [][]T

func CleanString

func CleanString(s string) string

func Contains

func Contains[T comparable](slice []T, target T) bool

func DoGetRequest

func DoGetRequest[T any](url string, headers map[string]string) (*T, error)

func DoPostRequest

func DoPostRequest[T any](url string, payload any) (*T, error)

func DoPostRequestWithHeaders

func DoPostRequestWithHeaders[T any](url string, payload any, headers map[string]string) (*T, error)

func ExtendURL

func ExtendURL(baseURL string, appendPath string) (*string, error)

ExtendURL extends urls, such as ExtendURL("https://example.com/api", "path/to/users")

func Find

func Find[T any](slice []T, predicate func(T) bool) *T

func ImageNameToPath

func ImageNameToPath(prefix, name string) string

ImageNameToPath converts a prefix and image name like "dining" and "toni_morrison" to "static/dining/toni_morrison.jpg"

func SaveToFile

func SaveToFile(data []byte, path string) error

func SmoothTime

func SmoothTime[T any](
	points []T,
	window time.Duration,
	get func(T) float64,
	set func(T, float64) T,
	ts func(T) time.Time,
) []T

SmoothTime applies a rolling average over a time window. - points: input slice (must be sorted by timestamp ascending) - window: duration around each point (e.g. 10 * time.Minute) - get: extracts a float64 from T - set: rebuilds T with the smoothed value - ts: extracts the timestamp from T

Types

type BrowserScraper

type BrowserScraper struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

func NewBrowserScraper

func NewBrowserScraper() *BrowserScraper

func (*BrowserScraper) Close

func (bs *BrowserScraper) Close()

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache[T any](name string, expiration time.Duration, fetchFunc func() (T, error)) *Cache[T]

func (*Cache[T]) ForceRefresh

func (c *Cache[T]) ForceRefresh() (T, error)

ForceRefresh forces a synchronous refresh

func (*Cache[T]) Get

func (c *Cache[T]) Get() (T, error)

type TableData

type TableData struct {
	Caption string
	Headers []string
	Rows    []rowData
}

func ScrapeTable

func ScrapeTable(sel *goquery.Selection) TableData

Directories

Path Synopsis
Package timeutils includes all time-related utils.
Package timeutils includes all time-related utils.

Jump to

Keyboard shortcuts

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