repositorypackage
0.0.0-20231030094300-cb028e65de09
Repository: https://github.com/ac5tin/usefulgo.git
Documentation: pkg.go.dev
# README
UsefulGo
Get Started
import (
uf "github.com/ac5tin/usefulgo"
)
Array
ArrContains
// ArrContains check is array contains a string
containstring := uf.ArrContains(arrstring,str)
ArrRMS
// ArrRMS removes string element from array (ordered)
uf.ArrRMS(&arr,str)
ArrRMiF and ArrRmiS (remove array elemet by index (fast and slow))
- ArrRmiF (Fast array index remover but doesnt maintain order)
- ArrRmiS (Slow array index remover but maintains order)
NewArrRmiF().String(&stringarr,3)
NewArrRmiS().Int(&intarr,3)
Binary
GetBytes
// GetBytes returns binary byte slices
byteslices,err := uf.GetBytes(x)
CSV
CSVParser
// CSVParser parses csv and runs callback function
reader := bytes.NewReader(byteslice)
r := csv.NewReader(reader)
err := uf.CSVParser(r,func(res []string,chunk int){
})
CSVParserH
// // CSVParserH parses csv with headers and runs callback function
reader := bytes.NewReader(byteslice)
r := csv.NewReader(reader)
err := uf.CSVParserH(r,func(res []map[string]string,chunk int){
})
Hash
HashPassword
// HashPassword returns hashed version of password
hashed,err := uf.HashPassword(pw,cost)
CheckPasswordHash
// CheckPasswordHash compares hashes between password string
cmp := uf.CheckPasswordHash(pw,hashed)
Mapfields
// Mapfields - returns subset map
mf := uf.Mapfields(d, fields) //d is of type map[string]interface{}
Hashmap
// Hashmap hashes a map using sha256 and returns the hash as string
mfhash, err := uf.Hashmap(mf)
Random
RandString
// RandString generates random string
rnd := uf.RandString(5)
String
RmDash
// RmDash removes dashes from strings
newstr := uf.RmDash(oldstr)
UUID
GenUUIDV4
uuid := uf.GenUUIDV4()
Math
IntAbs
x := -5
absx := uf.IntAbs(x) // returns 5
Compression
Compress, Decompress
NewCmpr().Compress(data,"xz") // gz for gzip, xz for LZMA2 xz
NewCmpr().Decompress(data,"xz")
Parsing
NumParse, FloatParse
NumParse[int64]("123") // parse string to int64
FloatParse[float32]("1.12") // parse string to float32