Documentation ¶
Index ¶
- func Alter[T comparable](value T, fallback T) T
- func ClearDirectory(dir string) error
- func ConcatStr(sep string, str ...string) string
- func Contains[T comparable](items []T, item T) bool
- func CreateDirectory(path string) error
- func DetectMime(data []byte) *mimetype.MIME
- func ErrorOf(res any, err error) error
- func Extension(file string) string
- func ExtractAlphaNum(str string, includes ...string) string
- func ExtractAlphaNumPersian(str string, includes ...string) string
- func ExtractNumbers(str string) string
- func FileExists(path string) (bool, error)
- func FindFile(dir string, pattern string) []string
- func FormatNumber(format string, v ...any) string
- func FormatRx(data, pattern, repl string) string
- func GetSubDirectory(dir string) ([]string, error)
- func HasError(err error) bool
- func If[T any](cond bool, yes T, no T) T
- func IsDirectory(path string) (bool, error)
- func IsErrorOf(tag string, err error) bool
- func NumberedFile(dir, name, file string) (string, error)
- func PanicOnError(err error)
- func PrettyLog(data any)
- func PrettyLogIndent(data any)
- func RandomString(n uint) (string, error)
- func RandomStringFromCharset(n uint, letters string) (res string, err error)
- func Slugify(str ...string) string
- func SlugifyPersian(str ...string) string
- func TaggedError(tags []string, format string, args ...any) error
- func Try(e error, fail func(e error), pass func(), finally ...func(e error))
- func VarOrPanic[T any](res T, err error) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Alter ¶ added in v1.0.1
func Alter[T comparable](value T, fallback T) T
Alter return fallback if value is empty
func ClearDirectory ¶
ClearDirectory delete all files and sub-directory in directory
func Contains ¶
func Contains[T comparable](items []T, item T) bool
Contains check if slice contains item
func CreateDirectory ¶
CreateDirectory create nested directory
func DetectMime ¶
DetectMime detect file mime info from content
func ExtractAlphaNum ¶
ExtractAlphaNum extract alpha and numbers from string [a-zA-Z0-9]
func ExtractAlphaNumPersian ¶
ExtractAlphaNumPersian extract persian alpha, alpha and numbers from string [ا-یa-zA-Z0-9]
func ExtractNumbers ¶
ExtractNumbers extract numbers from string
func FormatNumber ¶
FormatNumber format number with comma separator
func FormatRx ¶
FormatRx format string using regex pattern use () for group and $1, $2 for output placeholder example FormatRx("123456", `^(\d{3})(\d{2})(\d{1})$`, "($1) $2-$3")
func GetSubDirectory ¶
GetSubDirectory get list of sub directories
func IsDirectory ¶
IsDirectory check if path is directory
func NumberedFile ¶
NumberedFile generate unique numbered file until 10000000, e.g. file.txt file-1.txt, file-2.txt
func PrettyLogIndent ¶
func PrettyLogIndent(data any)
PrettyLogIndent log data to output using json format with indent
func RandomString ¶
RandomString generate random string from Alpha-Num Chars
func RandomStringFromCharset ¶
RandomStringFromCharset generate random string from character list
func SlugifyPersian ¶
SlugifyPersian make slugify string for persian string
func TaggedError ¶
TaggedError generate a tagged error
func VarOrPanic ¶
VarOrPanic get function result (T, error)
if result has error generate panic return T otherwise
Types ¶
This section is empty.