utils

package
v0.0.0-...-cbc9d59 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendSlices

func AppendSlices[T any](slices ...[]T) []T

AppendSlices is _not_ an efficient function by any means.

func BuildRequestEndpoint

func BuildRequestEndpoint(baseEndpoint, path string) string

func DecodeB64

func DecodeB64(data string) ([]byte, error)

DecodeB64 decodes data stored as a base64 string into bytes.

func EncodeB64

func EncodeB64[T BytesLike](data T) string

EncodeB64 encodes arbitrary string or bytes into a base64 string.

func FormatTime

func FormatTime(t time.Time, withUtcOffset bool) string

func FormatTimeUTC

func FormatTimeUTC(t time.Time) string

func FormatTimeWithZone

func FormatTimeWithZone(t time.Time, tz string, withUtcOffset bool) string

func FromPointer

func FromPointer[T any](val *T) (T, bool)

FromPointer returns the dereferenced value of a pointer, along with a bool representing whether a nil value was passed, and thus, a zero value for the value's underlying type returned. If val is nil, the zero value for val's underlying type is returned, along with false.

func HttpClientWithTimeout

func HttpClientWithTimeout(timeout time.Duration) *http.Client

func SHA256

func SHA256[T BytesLike](data T) (sum []byte)

SHA256 returns the SHA256 sum of the passed bytes/string as bytes.

func SHA256Hex

func SHA256Hex[T BytesLike](data T) (sumHex string)

SHA256Hex returns the result of SHA256 as a human-readable string.

func SHA3

func SHA3[T BytesLike](data T) (sum []byte)

SHA3 returns the SHA3-256 sum of the passed bytes/string, as bytes.

func SHA3Hex

func SHA3Hex[T BytesLike](data T) (sumHex string)

SHA3Hex returns the result of SHA3 as a human-readable string.

func SliceFirst

func SliceFirst[T any](data []T) (first T)

func SliceIncludes

func SliceIncludes[T comparable](data []T, want T) (found bool)

func SliceLast

func SliceLast[T any](data []T) (last T)

func TimeoutFromContext

func TimeoutFromContext(ctx context.Context) (time.Duration, bool)

func ToLocalTime

func ToLocalTime(t time.Time) time.Time

func ToPointer

func ToPointer[T any](val T) *T

ToPointer returns the pointer value of whatever is passed to it.

func UnmarshalConfig

func UnmarshalConfig(data []byte, confType ConfigFileType, dest any) error

func Wait

func Wait(ctx context.Context, d time.Duration)

Types

type BytesLike

type BytesLike interface{ ~string | []byte }

BytesLike is any string or byteslice.

type ConfigFileType

type ConfigFileType uint8
const (
	JsonConfig ConfigFileType
	YamlConfig
	TomlConfig
)

func ConfigFileTypeFromExtension

func ConfigFileTypeFromExtension(ext string) ConfigFileType

Jump to

Keyboard shortcuts

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