util

package
v0.0.0-...-f587f52 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: ISC Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertColorToInt32

func ConvertColorToInt32(c color.RGBA) int32

ConvertColorToInt32 will convert 3 uint8s into one int32

func ExtractNode

func ExtractNode(content string, fn extractNodeCondition) (*html.Node, error)

ExtractNode will select the first node to match extractNodeCondition, for example res, err := ExtractNode(string(content), func(str string) bool { return str == "title" })

func ExtractNodeText

func ExtractNodeText(n *html.Node, buf *bytes.Buffer)

func FormattedNum

func FormattedNum(num int64) string

FormattedNum will insert commas as necessary in large numbers

func FormattedTime

func FormattedTime(secondsIn int64) string

FormattedTime will turn seconds into a pretty time representation

func FormattedUserTag

func FormattedUserTag(u discord.User) string

FormattedUserTag will return the user#discrim if it's non-0 otherwise just username

func GetUserMention

func GetUserMention(id int64) string

GetUserMention will return a formatted user mention from an id

func HeadLinesLimit

func HeadLinesLimit(s string, limit int) string

HeadLinesLimit will take the first amount of lines that fit into the X char limit If the string does not consist of split lines, instead just fit the first amount of chars.

func JoinInt64AndStr

func JoinInt64AndStr(int int64, str string) string

JoinInt64AndStr will join and add a plural s to the str if int is not 1, for example, "0 hours", "1 hour", "2 hours".

func JoinInt64Slice

func JoinInt64Slice(i []int64, sep string, prefix string, suffix string) string

JoinInt64Slice will join i with sep

func JoinIntAndStr

func JoinIntAndStr(int int, str string) string

JoinIntAndStr is a wrapper for JoinInt64AndStr

func LogPanic

func LogPanic()

func NewInterface

func NewInterface(typ reflect.Type, data []byte) (interface{}, error)

func ParseHexColorFast

func ParseHexColorFast(s string) (c color.RGBA, err error)

ParseHexColorFast will take a hex string, and convert it to a color.RGBA

func RegisterHttpBashRequests

func RegisterHttpBashRequests()

func RequestUrl

func RequestUrl(url string, method string) ([]byte, *http.Response, error)

RequestUrl will return the bytes of the body of url

func RequestUrlFn

func RequestUrlFn(url string, method string, fn func(req *http.Request)) ([]byte, *http.Response, error)

RequestUrlFn will execute fn on req, then return the bytes of the body of url

func RequestUrlReq

func RequestUrlReq(req *http.Request) ([]byte, *http.Response, error)

RequestUrlReq will return the bytes of the body of request

func RequestUrlRetry

func RequestUrlRetry(urls []string, method string, code int) (bytes []byte)

RequestUrlRetry will return the bytes of the body of the first successful url

func RetryFunc

func RetryFunc(fn retryFunction, n int, delayMs time.Duration) ([]byte, error)

RetryFunc will re-try fn by n number of times, in addition to one regular try

func SliceContains

func SliceContains[T comparable](s []T, e T) bool

SliceContains will return if slice s contains e

func SliceEqual

func SliceEqual[T comparable](a []T, b []T) bool

SliceEqual returns true if all bytes of a and b are the same

func SliceJoin

func SliceJoin[T any](s []T, sep string, c func(s T) *string) string

SliceJoin will join any slice based on the property or value that c returns

func SliceRemove

func SliceRemove[T comparable](s []T, m T) []T

SliceRemove will remove m from s

func SliceRemoveIndex

func SliceRemoveIndex[T comparable](s []T, i int) []T

SliceRemoveIndex will remove index i from s

func SliceReverse

func SliceReverse[S ~[]T, T any](s S)

SliceReverse will reverse the order of s

func SliceSortAlphanumeric

func SliceSortAlphanumeric[S ~[]T, T string](s S)

SliceSortAlphanumeric will sort a string slice alphanumerically

func SlicesCondition

func SlicesCondition[T comparable](s []T, c func(s T) bool) bool

SlicesCondition will return if all values of []T match condition c

func TailLinesLimit

func TailLinesLimit(s string, limit int) string

TailLinesLimit will take the last amount of lines that fit into the X char limit. If the string does not consist of split lines, instead just fit the last amount of chars.

Types

This section is empty.

Jump to

Keyboard shortcuts

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