The MrAndreID/GoHelpers package is a collection of functions in the go language.
To use The MrAndreID/GoHelpers package, you must follow the steps below:
go get -u github.com/MrAndreID/gohelpersgohelpers.ErrorMessage("error loading the .env file", ".env file not found.")Output:
2021-02-15 18:45:18 [ ERROR ] Message : error loading the .env file.
2021-02-15 18:45:18 [ ERROR ] Detail : .env file not found.fmt.Println(gohelpers.JSONEncode(map[string]interface{}{"First Name": "Andrea", "Last Name": "Adam"}))Output:
{"First Name":"Andrea","Last Name":"Adam"}fmt.Println(gohelpers.Bytes(4))Output:
[95 113 200 231]fmt.Println(gohelpers.RandomByte(32))Output:
1UlrTYbNJioQPyBEKpV5BFtgqV6t5fEvjSaO8ApGRHs=fmt.Println(gohelpers.Random("str", 10))Output:
XBMUH3qvXhfmt.Println(gohelpers.Random("int", 4))Output:
6111fmt.Println(gohelpers.GenerateKey(32))Output:
7f2f9d692d200e20133428c832b80f8e21702437fcd28ba2ac8c5aaa3a978b2dkey := gohelpers.GenerateKey(32)
encryptedData, err := gohelpers.Encrypt(key, "Andrea Adam")
if err != nil {
gohelpers.ErrorMessage("something went wrong when encrypting data", err)
}
fmt.Println(encryptedData)Output:
b9ab3d8bde4092791b50142be86dfdc70688d81f42fa4aa06c88bcb1af6dfaa4f6c920ec157874key := gohelpers.GenerateKey(32)
plainText, err := gohelpers.Decrypt(key, "b9ab3d8bde4092791b50142be86dfdc70688d81f42fa4aa06c88bcb1af6dfaa4f6c920ec157874")
if err != nil {
gohelpers.ErrorMessage("something went wrong when decrypting data", err)
}
fmt.Println(plainText)Output:
Andrea Adamfmt.Println("Andrea" + gohelpers.GetNewLine() + "Adam")Output:
Andrea
Adammap1 := map[string]interface{}{"FirstName": "Andrea", "LastName": "Adam"}
map2 := map[string]interface{}{"Age": 21}
map3 := map[string]interface{}{"FirstName": "Andrea", "MidName": nil, "LastName": "Adam"}
fmt.Println(gohelpers.MergeMaps(map1, map2, map3))Output:
map[Age:21 FirstName:Andrea LastName:Adam MidName:<nil>]key := gohelpers.GenerateKey(32)
encryptedKey, err := gohelpers.GenerateEncryptedKey([]string{"Andrea", "Adam"}, "_", key)
if err != nil {
gohelpers.ErrorMessage("something went wrong when generating encrypted key", err)
}
fmt.Println(encryptedKey)Output:
ccaa9be63b4699a53166e1cf4a0086ff3ced25dca2f0672b9cb22309f5270087e7947cb643e579key := gohelpers.GenerateKey(32)
encryptedKey, err := gohelpers.GenerateEncryptedKeyWithDatetime([]string{"Andrea", "Adam"}, "_", key, time.Now())
if err != nil {
gohelpers.ErrorMessage("something went wrong when generating encrypted key with datetime", err)
}
fmt.Println(encryptedKey)Output:
4e9206fc51372eb6f983a06abdfdb23e7cff0cf32d8f418997428547ed6aef438274fa6054e9d63c96c9c929a6da4c2268700da5d0fe3f06f348a3key := gohelpers.GenerateKey(32)
data, err := gohelpers.UngenerateEncryptedKey("ccaa9be63b4699a53166e1cf4a0086ff3ced25dca2f0672b9cb22309f5270087e7947cb643e579", "_", key)
if err != nil {
gohelpers.ErrorMessage("something went wrong when ungenerating encrypted key", err)
}
fmt.Println(data)Output:
[Andrea Adam]key := gohelpers.GenerateKey(32)
encryptedHash, encryptedSalt, err := gohelpers.GenerateHashAndSalt("Andrea Adam", 32, key, 5)
if err != nil {
gohelpers.ErrorMessage("something went wrong when generating hash and salt", err)
}
fmt.Println("Hash : " + encryptedHash + ", Salt : " + encryptedSalt)Output:
Hash : 18f65095a8a2ad99851072aee8801c73eea67e2fb18866e8b96aaf4fdd996a879ee1a7987dbd2e9cf6803de30b8224eec77c63e0b9fac91e8c36b1c7fbe54589bd28bec89c774d3f6b8ea7b411d6edd8ef07630cf9689e4b, Salt : 2b4e42cf347c74ff1b1e28b99a3d50102313b022b5eac24ba1ba1287c3913c4d878cc94ae3def9908f6574e9e2d78777c993dc147dc93a7e13eccd9ecc418e4205acb763bc623693key := gohelpers.GenerateKey(32)
encryptedHash, encryptedSalt, err := gohelpers.GenerateHashAndSalt("Andrea Adam", 32, key, 5)
if err != nil {
gohelpers.ErrorMessage("something went wrong when generating hash and salt", err)
}
fmt.Println(gohelpers.VerifyHashAndSalt("Andrea Adam", encryptedHash, encryptedSalt, key))Output:
trueFull Example can be found on the Go Playground website.
I use SemVer for versioning. For the versions available, see the tags on this repository.
Andrea Adam - MrAndreID
MIT licensed. See the LICENSE file for details.
Documentation for Go Language can be found on the Go Language website.
Documentation can be found on https://go.dev/.