util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UpperEnglishLetters    = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	LowerEnglishLetters    = "abcdefghijklmnopqrstuvwxyz"
	UpperUnicodeLetters    = UpperEnglishLetters + "ÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÈÉẺẼẸÊỀẾỂỄỆÌÍỈĨỊÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÙÚỦŨỤƯỪỨỬỮỰ"
	LowerUnicodeLetters    = LowerEnglishLetters + "àáảãạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệìíỉĩịòóỏõọôồốổỗộơờớởỡợùúủũụưừứửữự"
	DecimalDigits          = "0123456789"
	EnglishLetters         = UpperEnglishLetters + LowerEnglishLetters
	UnicodeLetters         = UpperUnicodeLetters + LowerUnicodeLetters
	AlphaNumericCharacters = EnglishLetters + DecimalDigits
)

Some alphabets

Variables

View Source
var CompiledRegex = struct {
	DecimalString *regexp.Regexp
	HeximalString *regexp.Regexp
}{
	DecimalString: regexp.MustCompile("^[0-9]+$"),
	HeximalString: regexp.MustCompile("^[0-9a-f]+$"),
}

CompiledRegex contains some compiled common regex

Functions

func ArrayContains

func ArrayContains[R comparable](a []R, v R) bool

ArrayContains checks if array a[] contains value v or not

func CloseSilently

func CloseSilently(ctx context.Context, close func() error)

CloseSilently closes and write log if an error occurs

func IsDecimalString

func IsDecimalString(s string) bool

IsDecimalString checks if string contains only decimal digits or not

func IsHeximalString

func IsHeximalString(s string) bool

IsHeximalString checks if string contains only heximal digits or not

func RandomDecimalString

func RandomDecimalString(n int) string

RandomDecimalString generates a random string consisting of decimal digits

func RandomHeximalString

func RandomHeximalString(n int) string

RandomHeximalString generates a random string consisting of heximal digits

func RandomNaturalNumber

func RandomNaturalNumber(n int) int

RandomNaturalNumber generates a random natural number that is less than n

func RandomString

func RandomString(n int, alphabet string) string

RandomString generates a random string consisting of characters in the provided alphabet

func ToArrayString

func ToArrayString(a []interface{}) ([]string, bool)

ToArrayString converts from array of interface{} to array of string

func ToString

func ToString(any interface{}) string

ToString converts anything to string

Types

This section is empty.

Jump to

Keyboard shortcuts

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