util

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsString

func ContainsString(slice []string, s string) bool

ContainsString checks whether the given string slice contains the string provided.

func GenerateRandomBase64String

func GenerateRandomBase64String(n int) (string, error)

GenerateRandomBase64String returns a string with n random bytes securely generated using the system's default CSPRNG in base64 encoding. The resulting string might not be of length n as the encoding for the raw bytes generated may vary.

An error will be returned if reading from the secure random number generator fails, at which point the returned result should be discarded and not used any further.

func GenerateRandomBytes

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

GenerateRandomBytes returns n random bytes securely generated using the system's default CSPRNG.

An error will be returned if reading from the secure random number generator fails, at which point the returned result should be discarded and not used any further.

func GenerateRandomHexString

func GenerateRandomHexString(n int) (string, error)

GenerateRandomHexString returns a string with n random bytes securely generated using the system's default CSPRNG in hexadecimal encoding. The resulting string might not be of length n as the encoding for the raw bytes generated may vary.

An error will be returned if reading from the secure random number generator fails, at which point the returned result should be discarded and not used any further.

func GenerateRandomString

func GenerateRandomString(n int, ranges []CharRange, extra string) (string, error)

GenerateRandomString returns a string with n random bytes securely generated using the system's default CSPRNG. The characters within the generated string will either be part of one ore more supplied range of characters, or based on characters in the extra string supplied.

An error will be returned if reading from the secure random number generator fails, at which point the returned result should be discarded and not used any further.

func GetEnv

func GetEnv(key string, defaultVal string) string

func GetEnvAsBool

func GetEnvAsBool(key string, defaultVal bool) bool

func GetEnvAsInt

func GetEnvAsInt(key string, defaultVal int) int

func GetEnvAsStringArr

func GetEnvAsStringArr(key string, defaultVal []string, separator ...string) []string

GetEnvAsStringArr reads ENV and returns the values split by separator.

func GetEnvAsStringArrTrimmed

func GetEnvAsStringArrTrimmed(key string, defaultVal []string, separator ...string) []string

GetEnvAsStringArrTrimmed reads ENV and returns the whitespace trimmed values split by separator.

func GetEnvEnum

func GetEnvEnum(key string, defaultVal string, allowedValues []string) string

func GetProjectRootDir

func GetProjectRootDir() string

GetProjectRootDir returns the path as string to the project_root for a **running application**. Note: This function should not be used for generation targets (go generate, make go-generate). Thus it's explicitly excluded from the build tag scripts, see instead: * /scripts/get_project_root_dir.go * ./get_project_root_dir_scripts.go (delegates to above) https://stackoverflow.com/questions/43215655/building-multiple-binaries-using-different-packages-and-build-tags

Types

type CharRange

type CharRange int
const (
	CharRangeNumeric CharRange = iota
	CharRangeAlphaLowerCase
	CharRangeAlphaUpperCase
)

Jump to

Keyboard shortcuts

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