helpers

package
v0.0.0-...-9f41b84 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func After

func After(value string, a string) string

After Get substring after a string.

func BcryptCompare

func BcryptCompare(hash string, password string) error

BcryptCompare - compares a bcrypt hashed password with its possible plaintext equivalent. Returns nil on success, or an error on failure.

func BcryptHash

func BcryptHash(password string) (string, error)

BcryptHash - generate hashed password.

func Before

func Before(value string, a string) string

Before Get substring before a string.

func Between

func Between(value string, a string, b string) string

Between Get substring between two strings.

func BytesFormat

func BytesFormat(inputNum float64, precision int) string

BytesFormat - format bytes to MB...

func Contains

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

Contains - check if the slice of strings containt the given string

func ConvertToBool

func ConvertToBool(value interface{}) bool

ConvertToBool convert any data type to bool

func ConvertToFloat64

func ConvertToFloat64(value interface{}) float64

ConvertToFloat64 convert any data type to float64

func ConvertToInteger

func ConvertToInteger(value interface{}) int

ConvertToInteger convert any data type to specific type

func ConvertToString

func ConvertToString(value interface{}) string

ConvertToString convert any data type to specific type

func DecodeBase64

func DecodeBase64(str string) ([]byte, error)

DecodeBase64 - decode base64 string

func DecodeURLBase64

func DecodeURLBase64(str string) ([]byte, error)

DecodeURLBase64 - decode base64 string

func Decrypt

func Decrypt(ciphertext []byte, key []byte) (plaintext []byte, err error)

Decrypt decrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Expects input form nonce|ciphertext|tag where '|' indicates concatenation.

Example
key := []byte("9d8b23c2529ced916abaf60599fb3110")
text, _ := hex.DecodeString("537235e0ba1c4551c1787ab68ceb4bc3c6e738f0e3b3e8656322932e2a56969b4bcf5afb53e07d082b5cd61e8a451433")

doTest, _ := Decrypt(text, key)

fmt.Printf("%s\n", doTest)
// fmt.Println(err)
Output:

Testing encrypt func

func Deserialize

func Deserialize(src []byte, dst interface{}) error

Deserialize decodes a value using gob.

Example
key := []byte("9d8b23c2529ced916abaf60599fb3110")
text, _ := hex.DecodeString("537235e0ba1c4551c1787ab68ceb4bc3c6e738f0e3b3e8656322932e2a56969b4bcf5afb53e07d082b5cd61e8a451433")

doTest, _ := Decrypt(text, key)

fmt.Printf("%s\n", doTest)
// fmt.Println(err)
Output:

Testing encrypt func

func Difference

func Difference(slice []string, slice2 []string) []string

Difference - returns the values in slice1 that are not present in any of the other slices.

func EncodeBase64

func EncodeBase64(str []byte) string

EncodeBase64 - encode bytes to base64 string

func EncodeURLBase64

func EncodeURLBase64(str []byte) string

EncodeURLBase64 - encode bytes to base64 string

func Encrypt

func Encrypt(plaintext []byte, key []byte) (ciphertext []byte, err error)

Encrypt encrypts data using 256-bit AES-GCM. This both hides the content of the data and provides a check that it hasn't been altered. Output takes the form nonce|ciphertext|tag where '|' indicates concatenation.

Example
key := []byte("9d8b23c2529ced916abaf60599fb3110")
text := []byte("Testing encrypt func")

doTest, _ := Encrypt(text, key)

fmt.Printf("%x\n", doTest)
Output:

func GetCookie

func GetCookie(name string, request *http.Request) (string, error)

GetCookie - get the cookies from the request.

func RandomBytes

func RandomBytes(length int) []byte

RandomBytes - generate random bytes

func RandomString

func RandomString(length int) string

RandomString return random string by length

func Serialize

func Serialize(src interface{}) ([]byte, error)

Serialize encodes a value using gob.

func SetCookie

func SetCookie(cookie http.Cookie, response http.ResponseWriter)

SetCookie - set cookies to the response.

func Size

func Size(value interface{}) float64

Size return size of string or float64 or float32 or slice

Types

This section is empty.

Jump to

Keyboard shortcuts

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