util

package module
v0.0.0-...-7ea71f4 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Unlicense Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const SimpleDateFormat = "02/01/2006"

Variables

This section is empty.

Functions

func CreateDir

func CreateDir(dirName string) error

func DateDifferenceInDays

func DateDifferenceInDays(t1 time.Time, t2 time.Time) float64

DateDifferenceInDays returns the difference in days (including fractions) from t1 to t2

func EncodeImageAsDataUrl

func EncodeImageAsDataUrl(img image.Image) (*string, error)

func ExecuteCommand

func ExecuteCommand(command string, env []string, args ...string) (outStr string, errStr string, err error)

func ExitIfError

func ExitIfError(err error)

func FileExists

func FileExists(fileName string) bool

func FindString

func FindString(slice []string, val string) (int, bool)

Find takes a slice and looks for an element in it. If found it will return it's key, otherwise it will return -1 and a bool of false.

func FormatBytes

func FormatBytes(b int64) string

Format byte count value (e.g. file size) to human-readable form

func GetFieldInteger

func GetFieldInteger[T any](e *T, field string) int

func GetFieldString

func GetFieldString[T any](e *T, field string) string

func GetSimpleDateTimeString

func GetSimpleDateTimeString() string

GetSimpleDateTimeString returns a date string in the format 2006-01-02-15-04-05

func IntArrayToString

func IntArrayToString(a []int, delim string) string

func LogN

func LogN(base float64, number float64) float64

Calculate logN with arbitrary base

func MaxInt

func MaxInt(nums ...int) int

Returns the maximum value of the provided ints

func Merge

func Merge[T any](dst *T, src *T) error

func MinInt

func MinInt(nums ...int) int

Returns the minimum value of the provided ints

func NewTime

func NewTime(year, month, day int) time.Time

NewTime is a convenience function to create time.Time objects

func ParseInt

func ParseInt(v interface{}) (int, error)

func PrintMemUsage

func PrintMemUsage()

Prints statistics about current memory usage

func ReadFileToString

func ReadFileToString(fileName string) (*string, error)

func RemoveDuplicateStr

func RemoveDuplicateStr(strSlice []string) []string

func RemoveFirstStr

func RemoveFirstStr(s []string, r string) []string

func RemoveWhiteSpace

func RemoveWhiteSpace(s string) string

Remove all unicode white space from string

func Schedule

func Schedule(ctx context.Context, p time.Duration, o time.Duration, immediate bool, f func(time.Time)) time.Duration

Schedule calls function `f` with a period `p` offset by `o`. Run once immediately if immediate is set.

func SliceFindElement

func SliceFindElement[T comparable](slice []T, val T) (int, bool)

Takes a slice and looks for an element in it. If found it will return its index, otherwise it will return -1 and a bool of false.

func SliceFromMap

func SliceFromMap[K comparable, V any](m map[K]*V) []*V

Generate a slice from a map

func SliceFromMapKeys

func SliceFromMapKeys[K comparable, V any](m map[K]*V) []K

Generate a slice from a map's keys (generic)

func SliceJoinElems

func SliceJoinElems[T any](s []T, delim string) string

Joins the elements of the slice with separator delim

func SliceRemoveManyByIndex

func SliceRemoveManyByIndex[T comparable](s []T, indicesToRemove []int) ([]T, error)

Removes items at the given positions from slice s

func SliceRemoveOneByIndex

func SliceRemoveOneByIndex[T any](s []T, i int) ([]T, error)

Removes item at position i from slice s

func SliceWithIdsToMap

func SliceWithIdsToMap[V any](s []*V) map[int]*V

Generate a map from a slice with elements having an ID property

func SliceWithPointersFromSliceWithValues

func SliceWithPointersFromSliceWithValues[T any](values []T) []*T

Convert a slice of values to a slice of value pointers

func SliceWithValuesFromSliceWithPointers

func SliceWithValuesFromSliceWithPointers[T any](values []*T) []T

Convert a slice of value pointers to a slice of values

func SnakeCaseToCamelCase

func SnakeCaseToCamelCase(inputUnderScoreStr string) string

func StringToSnakeCase

func StringToSnakeCase(s string) string

func StripSpecialChars

func StripSpecialChars(s string) string

func Substr

func Substr(input string, start int, length int) string

NOTE: this isn't multi-Unicode-codepoint aware, like specifying skintone or

gender of an emoji: https://unicode.org/emoji/charts/full-emoji-modifiers.html

func UnzipSingleFileArchive

func UnzipSingleFileArchive(file []byte) ([]byte, error)

func UsesOnlyLetterAndNumbers

func UsesOnlyLetterAndNumbers(s string) bool

func ZipSingleFile

func ZipSingleFile(name string, content []byte) (*bytes.Buffer, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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