Documentation
¶
Overview ¶
Package utils includes all utility methods.
Index ¶
- Constants
- func ChunkArray[T any](arr []T, chunkSize int) [][]T
- func CleanString(s string) string
- func Contains[T comparable](slice []T, target T) bool
- func DoGetRequest[T any](url string, headers map[string]string) (*T, error)
- func DoPostRequest[T any](url string, payload any) (*T, error)
- func DoPostRequestWithHeaders[T any](url string, payload any, headers map[string]string) (*T, error)
- func ExtendURL(baseURL string, appendPath string) (*string, error)
- func Find[T any](slice []T, predicate func(T) bool) *T
- func ImageNameToPath(prefix, name string) string
- func SaveToFile(data []byte, path string) error
- func SmoothTime[T any](points []T, window time.Duration, get func(T) float64, set func(T, float64) T, ...) []T
- type BrowserScraper
- type Cache
- type TableData
Constants ¶
const NoExpiration time.Duration = -1
NoExpiration requests a cache that never expires.
Variables ¶
This section is empty.
Functions ¶
func ChunkArray ¶
func CleanString ¶
func Contains ¶
func Contains[T comparable](slice []T, target T) bool
func ExtendURL ¶
ExtendURL extends urls, such as ExtendURL("https://example.com/api", "path/to/users")
func ImageNameToPath ¶
ImageNameToPath converts a prefix and image name like "dining" and "toni_morrison" to "static/dining/toni_morrison.jpg"
func SaveToFile ¶
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 ¶
func NewBrowserScraper ¶
func NewBrowserScraper() *BrowserScraper
func (*BrowserScraper) Close ¶
func (bs *BrowserScraper) Close()