utils

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: BSD-3-Clause-Clear Imports: 12 Imported by: 0

README



Stellar Go Utils


Go Reference GitHub tag (latest SemVer) GitHub Workflow Status

Packages

Package Usage Docs
encryption Basic utilities for encrypting and decrypting values with AES-256-GCM encryption Go Docs
environment Parse environment variables to a predefined struct. Supports loading from .env files. Go Docs

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoValues = errors.New("no values provided")

Functions

func ChunkSlice added in v0.1.4

func ChunkSlice[T any](items []T, size int) [][]T

ChuckSlice creates a slice of slices of a max chunk size. Given a size argument of 4:

[]int{1,2,3,4,5,6,7,9}
// Becomes:
[][]int{ {1,2,3,4}, {5,6,7,8}, {9} }

func FilterPartialDuplicates added in v0.1.6

func FilterPartialDuplicates(in []string) []string

FilterPartialDuplicates takes a slice of strings and filters out items that are a partial match for other items in the slice. For example:

[]string{"thing1", "thing that has thing1", "thing2", "thing that has thing2", "thing3"}
// Becomes:
[]string{"thing1", "thing2", "thing3"}

func FindProjectRoot added in v0.1.0

func FindProjectRoot(depth int) (root string, err error)

FindProjectRoot finds the root of a Go project.

func HashFromStrings added in v0.1.3

func HashFromStrings(values ...string) (string, error)

HashFromStrings creates a SHA256 checksum from any number of input string values.

func IsBool

func IsBool(in any) bool

IsBool determines if a value is a boolean.

func IsFloat32

func IsFloat32(in any) bool

IsFloat32 determines if a value is a 32 bit float.

func IsFloat64

func IsFloat64(in any) bool

IsFloat64 determines if a value is a 64 bit float.

func IsInt

func IsInt(in any) bool

IsInt determines if a value is an integer.

func IsInt16

func IsInt16(in any) bool

IsInt16 determines if a value is a 16 bit integer.

func IsInt32

func IsInt32(in any) bool

IsInt32 determines if a value is a 32 bit integer.

func IsInt64

func IsInt64(in any) bool

IsInt64 determines if a value is a 64 bit integer.

func IsInt8

func IsInt8(in any) bool

IsInt8 determines if a value is an 8 bit integer.

func IsMap

func IsMap(in any) bool

IsMap determines if a value is a map.

func IsSlice

func IsSlice(in any) bool

IsSlice determines if a value is a slice.

func IsString

func IsString(in any) bool

IsString determines if a value is a string.

func IsStruct

func IsStruct(in any) bool

IsStruct determines if a value is a struct.

func IsTime

func IsTime(in any) bool

IsTime determines if a value is a time.Time object.

func IsUint

func IsUint(in any) bool

IsUint determines if a value is an unsigned integer.

func IsUint16

func IsUint16(in any) bool

IsUint16 determines if a value is an unsigned 16 bit integer.

func IsUint32

func IsUint32(in any) bool

IsUint32 determines if a value is an unsigned 32 bit integer.

func IsUint64

func IsUint64(in any) bool

IsUint64 determines if a value is an unsigned 64 bit integer.

func IsUint8

func IsUint8(in any) bool

IsUint8 determines if a value is an 8 bit unsigned integer.

func MapHasKey

func MapHasKey[K comparable, V any](m map[K]V, key K) bool

MapHasKey determines if a given map has an entry for a given key.

func MustHashFromStrings added in v0.1.7

func MustHashFromStrings(values ...string) string

MustHashFromStrings creates a SHA256 checksum from any number of input string values and panics on error.

func RandomBytes added in v0.0.5

func RandomBytes(n int) ([]byte, error)

RandomBytes generates cryptographically secure random bytes.

func RandomString added in v0.0.5

func RandomString(n int) (string, error)

RandomString generates a cryptographically secure random string.

func RandomStringFromLetterSet added in v0.0.5

func RandomStringFromLetterSet(n int, l string) (string, error)

RandomStringFromLetterSet generates a cryptographically secure random string from a given set of letters. RandomStringFromLetterSet is used as the backend for RandomString and RandomStringURLSafe.

func RandomStringURLSafe added in v0.0.5

func RandomStringURLSafe(n int) (string, error)

RandomStringURLSafe generates a cryptographically secure random string that is URL safe.

func Set added in v0.1.5

func Set[T comparable](a []T) []T

Set creates a slice of unique elements from an input slice. Order is not guaranteed.

Example

Set([]string{"one", "two", "two"}) // []string{"one", "two"}

func ShouldHashFromStrings added in v0.1.7

func ShouldHashFromStrings(values ...string) string

ShouldHashFromStrings creates a SHA256 checksum from any number of input string values. On error, a `__` joined string of input values is returned.

func SliceContains

func SliceContains[T comparable](arr []T, item T) bool

SliceContains determines if a given slice contains a given item.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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