helpers

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertInterfaceToBool

func ConvertInterfaceToBool(value interface{}) (bool, error)

ConvertInterfaceToBool will convert an interface `value` into boolean. The `value` is also supporting pointer interface.

func ConvertInterfaceToFloat

func ConvertInterfaceToFloat(value interface{}) (float64, error)

ConvertInterfaceToFloat will convert an interface `value` into float. The `value` is also supporting pointer interface.

func ConvertInterfaceToSlice

func ConvertInterfaceToSlice(value interface{}) interface{}

ConvertInterfaceToSlice will convert an interface `value` into slice. The `value` is also supporting pointer interface.

func ConvertInterfaceToString

func ConvertInterfaceToString(value interface{}) (string, error)

ConvertInterfaceToString will convert an interface `value` into string. The `value` is also supporting pointer interface.

func CurrFuncName

func CurrFuncName() string

CurrFuncName return the name of the current running function.

func CurrVersion

func CurrVersion() string

CurrVersion will return the current version, only support module mode binaries.

func DecodeJWT

func DecodeJWT(c echo.Context, claims jwt.Claims, secret string) error

DecodeJWT will decode JWT string into `claims` structure using a secret string.

func DeleteStringFromSlice

func DeleteStringFromSlice(slice []string, index int) []string

DeleteStringFromSlice will delete a string from a specific index of a slice.

func EncodeJWT

func EncodeJWT(claims jwt.Claims, secret string) (string, error)

EncodeJWT will encode JWT `claims` using a secret string and return a signed token as string.

func ExtractJWTFromHeader

func ExtractJWTFromHeader(c echo.Context) string

ExtractJWTFromHeader will extract JWT from `Authorization` HTTP header and returns as string.

func FindStringInSlice

func FindStringInSlice(slice []string, str string) int

FindStringInSlice returns the smallest index at which str == slice[index], or -1 if there is no such index.

func FloatInRange

func FloatInRange(i, min, max float64) float64

FloatInRange will return the floating point number provided in `i` if the number is between min and max. If `i` is less than `min` then it will return min number. If `i` is greater than `max` then it will return max.

func GetRandomNumberFromRange

func GetRandomNumberFromRange(min, max int) int

GetRandomNumberFromRange will generate and return a random integer from a range.

func HasStringInSlice

func HasStringInSlice(slice []string, str string, modifier func(str string) string) bool

if !slice.HasStringInSlice(src, "ee", modifier) { }

func HasTargetInSlice

func HasTargetInSlice[T comparable](slice []T, target T, modifiers ...func(T) T) bool

HasTargetInSlice tells whether slice contains target or false

func InterfaceStripTags

func InterfaceStripTags(data interface{}, trimSpace bool) interface{}

func IsFilesExistInDirectory

func IsFilesExistInDirectory(dir string, filesToCheck []string) (bool, error)

IsFilesExistInDirectory will check a file(s) is exist in a specific diretory or not. If you pass multiple files into `filesToCheck` slice then this function will chcek the existence of all those files. If one of the file doesn't exist, it will return `false`.

func JitterBackoff

func JitterBackoff(min, max time.Duration, attempt int) time.Duration
    select {
    case <-time.After(waitTime):
    case <-c.Done():
      return c.Err()
    }
}

func Join

func Join[T text](slice []T, sep string) string

Join converts a slice of text to a string, separated by sep.

func Max

func Max[T Int | Float](x, y T) T

Max returns a greater number of x and y, otherwise y. It supports only type parameters comparable with order operators (`<`, `<=`, `>` and `>=`).

func ParseBeanSystemFilesAndDirectorires

func ParseBeanSystemFilesAndDirectorires()

func PostDataStripTags

func PostDataStripTags(c echo.Context, trimSpace bool) (map[string]interface{}, error)

func SingleDo

func SingleDo[T any](ctx context.Context, key string, call func() (T, error), retry uint, ttl ...time.Duration) (data T, err error)

func SingleDoChan

func SingleDoChan[T any](ctx context.Context, key string, call func() (T, error), retry uint, ttl ...time.Duration) (data T, err error)

func StructStripTags

func StructStripTags(data interface{}, trimSpace bool) error

helpers.StructStripTags(&test, true)

Types

type CopyableMap

type CopyableMap map[string]interface{}

func (CopyableMap) DeepCopy

func (m CopyableMap) DeepCopy() map[string]interface{}

DeepCopy will create a deep copy of this map. The depth of this copy is all inclusive. Both maps and slices will be considered when making the copy. Keep in mind that the slices in the resulting map will be of type []interface{}, so when using them, you will need to use type assertion to retrieve the value in the expected type. Reference: https://stackoverflow.com/questions/23057785/how-to-copy-a-map/23058707

type CopyableSlice

type CopyableSlice []interface{}

func (CopyableSlice) DeepCopy

func (s CopyableSlice) DeepCopy() []interface{}

DeepCopy will create a deep copy of this slice. The depth of this copy is all inclusive. Both maps and slices will be considered when making the copy. Reference: https://stackoverflow.com/questions/23057785/how-to-copy-a-map/23058707

type Float

type Float interface {
	~float32 | ~float64
}

type Int

type Int interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Jump to

Keyboard shortcuts

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