Documentation
¶
Index ¶
- func B64DecodeMsg(b64Key string, offsetF ...int) ([]byte, error)
- func ChunkBy[T any](items []T, chunkSize int) (chunks [][]T)
- func Contains(s []string, str string) bool
- func CreateBytes(data any) []byte
- func CreateKey(key []byte) []byte
- func Die(msg string)
- func DifferenceInSlices(l1, l2 []string) ([]string, []string, []string)
- func GetEnvDefault(key string, defaultVal string) string
- func GetEnvOrDie(key string) string
- func InBetween(i, min, max int) bool
- func LinesFromReader(r io.Reader) []string
- func MaybeDie(err error, msg string)
- func Print(level, msg string)
- func RandomString(n int) string
- func TimePtr(t time.Time) time.Time
- func UrlToLines(url string, username string, password string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func B64DecodeMsg ¶
B64DecodeMsg decodes a base64 encoded key and returns a subset of the key starting from the specified offset.
Parameters:
- b64Key: The base64 encoded key to be decoded.
- offsetF: An optional integer representing the offset from which to start the subset of the key. If not provided, it defaults to 7.
Returns:
- []byte: The subset of the key starting from the specified offset.
- error: An error if the decoding or subset operation fails.
func ChunkBy ¶
ChunkBy splits a slice of items into smaller chunks of a specified size.
items: The slice of items to be split. chunkSize: The size of each chunk. [][]T: A slice of slices, where each slice represents a chunk of items.
func Contains ¶
Contains checks if a string is present in a slice of strings.
Parameters: - s: the slice of strings to search in. - str: the string to search for.
Returns: - bool: true if the string is found, false otherwise.
func CreateBytes ¶
CreateBytes encodes the given data to bytes using gob encoding.
data: the data to be encoded []byte: the encoded data as a byte slice
func CreateKey ¶
CreateKey generates a key for encryption.
key: The byte array used to generate the key. Returns: The generated key.
func Die ¶
func Die(msg string)
Die exits the program after logging an error message.
It takes a message as a parameter and does not return anything.
func DifferenceInSlices ¶
DifferenceInSlices Returns missing from List1 but in list 2 missing from List2 but in list 1 common in both
func GetEnvDefault ¶
GetEnvDefault retrieves the value of the environment variable specified by the key. If the environment variable does not exist, it returns the default value.
Parameters: - key: the name of the environment variable to retrieve. - defaultVal: the value to return if the environment variable does not exist.
Return: - string: the value of the environment variable or the default value.
func GetEnvOrDie ¶
GetEnvOrDie returns the value of the specified environment variable or exits the program.
It takes a key string as a parameter and returns a string value.
func InBetween ¶
InBetween checks if a number is within a given range.
Parameters:
- i: the number to check
- min: the minimum range value (inclusive)
- max: the maximum range value (inclusive)
Returns:
- bool: true if the number is within the range, false otherwise.
func LinesFromReader ¶
LinesFromReader returns an array of strings representing each line read from the provided io.Reader.
The function takes an io.Reader as a parameter and scans it line by line using a bufio.Scanner. Each line is then appended to the `lines` array. After scanning is complete, the function checks for any errors and calls the MaybeDie function if there is any error. Finally, the `lines` array is returned.
func MaybeDie ¶
MaybeDie is a function that checks if an error exists and calls the Die function with a formatted error message if it does.
Parameters: - err: the error to check. - msg: the message to include in the error message.
func Print ¶
func Print(level, msg string)
Print prints the given message with the specified log level.
Parameters:
- level: the log level to use (e.g. "INFO", "ERROR").
- msg: the message to be printed.
func RandomString ¶
func TimePtr ¶
TimePtr takes a time.Time parameter and returns the same time.Time value.
t: a time.Time parameter. Returns: a time.Time value.
func UrlToLines ¶
UrlToLines retrieves the contents of a URL and returns them line by line.
Parameters: - url: the URL to retrieve the contents from. - username: the username for basic authentication. If not needed, leave it empty. - password: the password for basic authentication. If not needed, leave it empty.
Returns: - lines: an array of strings containing the lines of the retrieved content.
Types ¶
This section is empty.