util

package
v0.0.0-...-091106e Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RecoverRoutineForever - this const is used to be passed to RunInSelfRecoverableGoRoutine
	// as maxPanics argument. It indicates that the RunInSelfRecoverableGoRoutine
	// will recover forever from panics
	RecoverRoutineForever = -1
)

Variables

This section is empty.

Functions

func AddPropToJSONString

func AddPropToJSONString(s, key string, prop interface{}) (string, error)

AddPropToJSONString receives the JSON string, key in the form of "part1.part2" and value and adds all the relevant parts to resulting JSON string For example, passing empty string and "Security.SessionKey" as key will create {"Security": {"SessionKey": val}} Does not support array values

func Decrypt

func Decrypt(ciphertext string, key []byte) (string, error)

Decrypt decrypts the previously encrypted text using pass

func DecryptJSON

func DecryptJSON(ciphertext, pass string, v interface{}) error

DecryptJSON decrypts to object

func Encrypt

func Encrypt(plaintext string, key []byte) (string, error)

Encrypt encrypts the given text with the password using AES and SHA256

func EncryptJSON

func EncryptJSON(v interface{}, pass string) (string, error)

EncryptJSON encrypts the given object by serializing to JSON and using Encrypt

func GoAndRespawn

func GoAndRespawn(f func(), maxPanics int, onDone func(isFailed bool))

GoAndRespawn - the function runs the f function as a go routine. If f panics, it will recover from the panic and re-run the function. If f finished without panic, then the go routine will finish. maxPanics - if f() paniced maxPanics times, then the routine will be stopped.

Use RecoverRoutineForever const to recover forever from panics

onDone - is a callback which executed when or f() finished gracefully or maxPanics occured.

It passes isFailed which indicates if f() finished gracefully or opaniced maxPanics times

func In

func In(slice interface{}, val interface{}) bool

In checks if val is in s slice

func IndexOf

func IndexOf(slice interface{}, val interface{}) int

IndexOf returns the index of an object in an array based on obj1 == obj2

func MapStrings

func MapStrings(arr []string, mapFunc func(int, string) string) []string

MapStrings with a translate function (like Array.map in JS)

func MarshalWithFilter

func MarshalWithFilter(v interface{}, filters ...string) ([]byte, error)

MarshalWithFilter the given struct while filtering out the given Fields The filters should be in the form of x.y where x and y are the JSON names (as in the JSON tags) Naive and slow implementation - might be rewritten if needed

func Max

func Max(a int, b int) int

Max returns the max between 2 ints

func Min

func Min(a int, b int) int

Min returns the min between 2 ints

func RandStr

func RandStr(strSize int) string

RandStr returns a random string of size strSize

func SecureRandomString

func SecureRandomString(size int, alphaOnly bool) string

SecureRandomString generate a secure random string of size that can be alpha or alphanum

func SortString

func SortString(arr []string)

SortString - sort an array of strings

func SplitAndTrim

func SplitAndTrim(s string) []string

SplitAndTrim , split by token "," and trim rach result

func SplitOrEmpty

func SplitOrEmpty(val string) (split []string)

SplitOrEmpty returns the value split by "," or empty array if val is empty

func ToGenericFilter

func ToGenericFilter(v interface{}, filters ...string) (interface{}, error)

ToGenericFilter translates an object to generic slices and maps while filtering the given fields

func ToIntf

func ToIntf(s interface{}) []interface{}

ToIntf converts a slice or array of a specific type to array of interface{}

func ToLower

func ToLower(s []string) []string

ToLower conerts a slice of strings to lower case

Types

This section is empty.

Jump to

Keyboard shortcuts

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