util

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmailRegex = regexp.MustCompile(`^[^@ \t\r\n]+@[^@ \t\r\n]+\.[^@ \t\r\n]+$`)
	PhoneRegex = regexp.MustCompile(`^[0-9]{3}[-\s\.]?[0-9]{4}([-\s\.]?[0-9]{4})?$`)
)
View Source
var Validator *validator.Validate

Functions

func FormatBytes

func FormatBytes(bytes uint64) string

func GetJwtString

func GetJwtString(id uint, name, role string) (string, error)

func GetJwtStringWithClaims

func GetJwtStringWithClaims(id uint, name, role string, custom map[string]any) (string, error)

func GetRawJwtString

func GetRawJwtString(claims jwt.MapClaims) (string, error)

func HTTPRequest

func HTTPRequest[T any](url string, method string, params map[string]string, payload map[string]any) (response *T, err error)

func In

func In[T comparable](key T, values ...T) bool

func Insert

func Insert[T any](slice []T, elem T, index uint) []T

func LastElem

func LastElem[T any](slice []T) T

func Move

func Move[T comparable](slice []T, elem T, to uint) []T

func NilOrBaseValue

func NilOrBaseValue[T, U any](v *T, fn func(*T) U, def U) U

func NilOrLazyValue

func NilOrLazyValue[T, U any](v *T, fn func(*T) *U) *U

func NilOrPtrCast

func NilOrPtrCast[U any](v any) *U

func NilOrValue

func NilOrValue[T, U any](v *T, obj *U) *U

func NotEmpty

func NotEmpty(s, def string) string

func NotEmptyFieldName

func NotEmptyFieldName(s any) (names []string)

NotEmptyFieldName Get the json tag name of a struct field that is not empty

func NotNil

func NotNil[T, U any](v *T, u *T) *T

func ProcessString

func ProcessString(str string, vars interface{}) string

func ProcessStringWithTPL

func ProcessStringWithTPL(tpl *template.Template, str string, vars interface{}) string

func RandomString

func RandomString(n int) string

func Remove

func Remove[T comparable](slice []T, elems ...T) []T

func RemoveByRef

func RemoveByRef[T any](slice []T, elems ...*T) []T

func Tenary

func Tenary[T any](cond bool, a, b T) T

func ToUint

func ToUint[T ~int | ~int8 | ~int16 | ~int32 | ~int64](n T) uint

func TransSlice

func TransSlice[T, U any](s []T, trans func(T) U) (us []U)

Types

type AtomPtr

type AtomPtr[T any] struct {
	// contains filtered or unexported fields
}

func (*AtomPtr[T]) Get

func (a *AtomPtr[T]) Get() *T

func (*AtomPtr[T]) Set

func (a *AtomPtr[T]) Set(v *T)

type CoPtrMap

type CoPtrMap[K, V any] struct {
	// contains filtered or unexported fields
}

func NewCoMap

func NewCoMap[K, V any]() *CoPtrMap[K, *V]

func (*CoPtrMap[K, V]) Delete

func (c *CoPtrMap[K, V]) Delete(k K)

func (*CoPtrMap[K, V]) Get

func (c *CoPtrMap[K, V]) Get(k K) *V

func (*CoPtrMap[K, V]) Has

func (c *CoPtrMap[K, V]) Has(k K) bool

func (*CoPtrMap[K, V]) LoadAndDelete

func (c *CoPtrMap[K, V]) LoadAndDelete(k K) *V

func (*CoPtrMap[K, V]) Range

func (c *CoPtrMap[K, V]) Range(f func(k K, v *V) error) (err error)

func (*CoPtrMap[K, V]) Set

func (c *CoPtrMap[K, V]) Set(k K, v *V)

Jump to

Keyboard shortcuts

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