# README
Utilities
Common utils
Usage
Quick usage
import "github.com/gflydev/core/utils"
newHello := utils.CopyStr("Hello world")
Bytes
// Random byte
myBytes := utils.RandByte(make([]byte, 15))
// Extend bytes
myBytes := utils.ExtendByte(myBytes, 5)
Token
// Random UNIQUE token
myToken := utils.Token()
# Functions
ComparePasswords func for a comparing password.
CopyByte returns a copy of byte slice in a new pointer.
CopyStr copies a string to make it immutable.
EqualByte reports whether a and b are the same length and contain the same bytes.
ExtendByte extends b to needLen bytes.
FileExt Extract extension of file.
GeneratePassword func for a making hash & salt with user password.
Getenv Get environment parameter (From .env file).
IncludeStr returns true or false if given string is in slice.
IndexOfStr returns index position in slice from given string If value is -1, the string does not found.
MD5 hash md5 from string value.
PrependByte prepends bytes into a given byte slice.
PrependByteStr prepends a string into a given byte slice.
QuoteStr escape special characters in a given string.
RandByte returns dst with a cryptographically secure string random bytes.
RandInt64 Generate a random number Int64 in rang [0, max)
NOTE:
Get error `G404 (CWE-338): Use of weak random number generator (math/rand instead of crypto/rand) (Confidence: MEDIUM, Severity: HIGH)` when use `rand.Intn(max)` from "math/rand".
ReflectType Get the name of a struct instance.
RenameFile Extract new file path.
RequestParam parse a specific request parameter string.
RequestPath parse request path string.
RequestURL parse request URL string.
Sha256 hash from list of arguments.
Token generate unique token.
UnpackArray Unpack an `arr` argument `any` but is exactly a type `[]any` Eg: We have `args` type `any`.
UnpackArrayT Unpack an `a` argument `any` but is exactly a type `[]T` Eg: We have `args` type `any`.
UnsafeBytes returns a byte pointer without allocation.
UnsafeStr returns a string pointer without allocation.