utils

package
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(src, dst string) (err error)

CopyFile copies a file from src to dst. If src and dst files exist, and are the same, then return success. Otherise, attempt to create a hard link between the two files. If that fail, copy the file contents from src to dst.

func DateRange

func DateRange(week, month, year int) (time.Time, time.Time, error)

DateRange takes optional week, month, and year. If all are 0, it returns the zero time range. If only year is provided, it returns the full year. If both month and year are provided, it returns the start and end of that month. If week and year are provided, it returns the start and end of that week. If only week or month is provided without a year, it's considered invalid.

func FlattenAliases

func FlattenAliases(aliases []models.Alias) []string

func FlattenArtistIDs

func FlattenArtistIDs(artists []*models.Artist) []int32

func FlattenArtistMbzIDs

func FlattenArtistMbzIDs(artists []*models.Artist) []uuid.UUID

func FlattenArtistNames

func FlattenArtistNames(artists []*models.Artist) []string

func FlattenMbzArtistCreditNames

func FlattenMbzArtistCreditNames(artists []mbz.MusicBrainzArtistCredit) []string

func FlattenSimpleArtistNames

func FlattenSimpleArtistNames(artists []models.SimpleArtist) []string

func IDFromString

func IDFromString(s string) string

func MoreThanOneString

func MoreThanOneString(s ...string) bool

Returns true if more than one string is not empty

func MoveFirstMatchToFront

func MoveFirstMatchToFront(slice []string, substring string) []string

MoveFirstMatchToFront moves the first string containing the substring to the front of the slice.

func ParseBool

func ParseBool(s string) (value, ok bool)

func ParseUUIDSlice

func ParseUUIDSlice(str []string) ([]uuid.UUID, error)

func RemoveInBoth

func RemoveInBoth(s, c []string) []string

Returns only items that are in one slice but not the other

func RemoveNonAscii

func RemoveNonAscii(s []string) []string

Returns the same slice, but with all entries that contain non ASCII characters removed

func Unique

func Unique(xs *[]string)

Removes duplicates in a string set

func UniqueIgnoringCase

func UniqueIgnoringCase(s []string) []string

Returns the same slice, but with all strings that are equal (with strings.EqualFold) included only once

func WriteError

func WriteError(w http.ResponseWriter, message string, code int)

Essentially the same as utils.WriteError(w, `{"error": "message"}`, code)

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, data any)

Sets content type and status code, and encodes data to json

Types

This section is empty.

Jump to

Keyboard shortcuts

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