utils

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 6 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func B64DecodeMsg

func B64DecodeMsg(b64Key string, offsetF ...int) ([]byte, error)

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

func ChunkBy[T any](items []T, chunkSize int) (chunks [][]T)

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

func Contains(s []string, str string) bool

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 CreateKey

func CreateKey(key []byte) []byte

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

func DifferenceInSlices(l1, l2 []string) ([]string, []string, []string)

DifferenceInSlices Returns missing from List1 but in list 2 missing from List2 but in list 1 common in both

func GetEnvDefault

func GetEnvDefault(key string, defaultVal string) string

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

func GetEnvOrDie(key string) string

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

func InBetween(i, min, max int) bool

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 MaybeDie

func MaybeDie(err error, msg string)

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 TimePtr

func TimePtr(t time.Time) time.Time

TimePtr takes a time.Time parameter and returns the same time.Time value.

t: a time.Time parameter. Returns: a time.Time value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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