utils

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CueEvaluatingJsonValue

func CueEvaluatingJsonValue(schemaName string, cueDef string, jsonValue []byte) ([]byte, error)

CueEvaluatingJsonValue - Simple func to build json from a CueLang definition Parameters: - schemaName: Main cue schema name to eval - cueDef: Cue document, contains Cue definitions - jsonValue: Use to as Cue values for evaluating

func CueValidateJson

func CueValidateJson(schemaName string, cueDef string, jsonBytes []byte) error

CueValidateJson - Simple func to validate json by cue definitions Parameters: - schemaName: Main cue schema name to eval - cueDef: Cue document, contains Cue definitions - jsonBytes: Use to as Cue values for evaluating

func CueValidateObject

func CueValidateObject(schemaName string, cueDef string, obj interface{}) error

Becareful with json ommitempty options. Prefer use CueValidateJson for raw payload before marshal to struct

func ExecuteWithRetry

func ExecuteWithRetry(exeFunc func() (interface{}, bool, error), retries int, sleepTime time.Duration) (interface{}, error)

func GenerateLongUUID

func GenerateLongUUID() string

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateUUID

func GenerateUUID() string

func GetFunctionName

func GetFunctionName(i interface{}) string

func GetHttpStatusCodeByErrorType added in v0.2.1

func GetHttpStatusCodeByErrorType(err error, defaultCode int) int

func GetLoggerFromContext

func GetLoggerFromContext(c echo.Context) logger.Logger

func GetMD5Hash

func GetMD5Hash(text string) string

GetMD5Hash -- get md5 hash from a string

func GetResourceIdFromParam

func GetResourceIdFromParam(c echo.Context, paramName string) int64

func GetSHA256Hash

func GetSHA256Hash(text string) string

GetSHA256Hash -- get sha_256 hash from a string

func GetSHA512Hash

func GetSHA512Hash(text string) string

GetSHA512Hash -- get sha_512 hash from a string

func IsCueError

func IsCueError(err error) bool

func IsDuplicatedError

func IsDuplicatedError(err error) bool

func IsSliceContains

func IsSliceContains[T constraints.Ordered](itemSlice []T, searchItem T) bool

func IsStringContainsAnyKeywords

func IsStringContainsAnyKeywords(s string, keywords []string) bool

func IsStringSliceCaseInsensitiveContains

func IsStringSliceCaseInsensitiveContains(stringSlice []string, searchString string) bool

IsStringSliceCaseInsensitiveContains -- check slice contain string

func LcFirst

func LcFirst(str string) string

LcFirst Lower case first char

func NewNotFoundError

func NewNotFoundError() error

NewNotFoundError creates a new error response representing a resource-not-found error (HTTP 404)

func RemoveStringSliceContains

func RemoveStringSliceContains(stringSlice []string, searchString string) []string

RemoveStringSliceContains -- check slice contain string and remove

func StringSlice

func StringSlice(s, sep string) []string

StringSlice -- slice string by separate

func ToCamel

func ToCamel(s string) string

ToCamel Converts a string to CamelCase

func ToCamelInitCaseKeepAll

func ToCamelInitCaseKeepAll(s string, initCase bool) string

ToCamelInitCaseKeepAll Converts a string to CamelCase

func ToDelimited

func ToDelimited(s string, del uint8) string

ToDelimited Converts a string to delimited.snake.case (in this case `del = '.'`)

func ToKebab

func ToKebab(s string) string

ToKebab Converts a string to kebab-case

func ToLowerCamel

func ToLowerCamel(s string) string

ToLowerCamel Converts a string to lowerCamelCase

func ToScreamingDelimited

func ToScreamingDelimited(s string, del uint8, screaming bool) string

ToScreamingDelimited Converts a string to SCREAMING.DELIMITED.SNAKE.CASE (in this case `del = '.'; screaming = true`) or delimited.snake.case (in this case `del = '.'; screaming = false`)

func ToScreamingKebab

func ToScreamingKebab(s string) string

ToScreamingKebab Converts a string to SCREAMING-KEBAB-CASE

func ToScreamingSnake

func ToScreamingSnake(s string) string

ToScreamingSnake Converts a string to SCREAMING_SNAKE_CASE

func ToSnake

func ToSnake(s string) string

ToSnake Converts a string to snake_case

func UcFirst

func UcFirst(str string) string

UcFirst Upper case first character

Types

type Error

type Error struct {
	Errors map[string]interface{} `json:"errors"`
}

func NewAccessForbiddenError

func NewAccessForbiddenError() Error

NewAccessForbiddenError creates a new error response representing an authorization failure (HTTP 403)

func NewError

func NewError(err error, msg string) Error

NewError creates a new error response

func NewValidationError

func NewValidationError(errs validator.ValidationErrors) Error

NewValidationError creates a new error response representing a data validation error (HTTP 400)

func (Error) Error

func (e Error) Error() string

func (Error) RawError

func (e Error) RawError() error

Jump to

Keyboard shortcuts

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