helpers

package
v0.0.0-...-9780e12 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

error_helpers.go

string_helpers.go

Index

Constants

This section is empty.

Variables

View Source
var EmailRegex = regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)

Email regex pattern

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hashedPassword string) bool

func ConfigLogger

func ConfigLogger()

func Contains

func Contains(slice []int, item int) bool

contains checks if a slice contains a particular element.

func EncryptAES

func EncryptAES(plaintext, key string) (string, error)

func GenerateJWTSecretKey

func GenerateJWTSecretKey(length int) (string, error)

func GetCurrentTimestampHex

func GetCurrentTimestampHex() string

func HashPassword

func HashPassword(password string) (string, error)

func LogError

func LogError(err error, msg string, depth ...int)

LogError logs error messages with context including the correct caller location.

func LogFatal

func LogFatal(err error, msg string, depth ...int)

LogFatal logs critical errors and terminates the application.

func LogInfo

func LogInfo(format string, args ...interface{})

LogInfo logs an informational message with formatting options.

func ParseHexSubstring

func ParseHexSubstring(hexStr string, byteOffset, byteLength int) (int, int, error)

parseHexSubstring extracts an integer value from a specified hex substring within a larger hex string, based on the offset and length in bytes.

func ParseHexSubstringBigInt

func ParseHexSubstringBigInt(hexStr string, byteOffset, byteLength int) (*big.Int, int, error)

ParseHexSubstringBigInt extracts a large integer value from a specified hex substring within a larger hex string, based on the offset and length in bytes, returning *big.Int.

func ParseHexToASCIIString

func ParseHexToASCIIString(hexStr string, byteOffset int, byteLength int) (string, int, error)

ParseHexToASCIIString converts a segment of a hex string starting at byteOffset for byteLength bytes into its ASCII string representation.

func PrettyPrintJSON

func PrettyPrintJSON(data any)

PrettyPrintJSON takes any data and prints it in an indented JSON format

func RespondWithError

func RespondWithError(w http.ResponseWriter, err error, message string, statusCode int, depth ...int)

RespondWithError logs the error, captures file/line, and sends a detailed error response.

func Splice

func Splice[T any](slice []T, start, count int, elementsToAdd []T) ([]T, []T)

Splice function to remove and optionally add elements to a slice.

func SplitIntoPairs

func SplitIntoPairs(input string) []string

splitIntoPairs splits a string into pairs of two characters.

func StopLogging

func StopLogging()

StopLogging stops the periodic flushing and closes log files.

func StructSliceToMapSlice

func StructSliceToMapSlice(slice any) ([]map[string]any, error)

StructSliceToMapSlice converts a slice of structs into a slice of map[string]any.

func StructToMap

func StructToMap(v any) (map[string]any, error)

StructToMap converts a struct to a map[string]any using JSON marshaling and unmarshaling.

func WrapError

func WrapError(err error) error

Helper function to wrap error with colored file and line context

Types

This section is empty.

Jump to

Keyboard shortcuts

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