helper

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package from https://github.com/gogf/gf

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CutLastString

func CutLastString(text, beginChar, endChar string) string

CutLastString 截取字符串中最后一段,以@beginChar开始,@endChar结束的字符 @text 文本 @beginChar 开始

func DeleteFile added in v1.1.2

func DeleteFile(filepath string) error

DeleteFile will delete filepath permanently. Returns an error in case there's any.

func EllipseTruncate

func EllipseTruncate(s string, max int) string

func GenerateRandomString added in v1.1.2

func GenerateRandomString(n int) (string, error)

GenerateRandomString generates a cryptographically random, alphanumeric string of length n.

func GetFile added in v1.1.2

func GetFile(filepath string) (*os.File, error)

GetFile will open filepath. Returns a tuple with a file and an error in case there's any.

func GoRecover

func GoRecover(f func(), name string)

GoRecover take a function as input, if the function panics, the panic will be recovered and the error will be returned

func IsBlank

func IsBlank(value string) bool

func IsEmpty

func IsEmpty(value any) bool

IsEmpty checks whether given <value> empty. It returns true if <value> is in: 0, nil, false, "", len(slice/map/chan) == 0, or else it returns false.

func IsLetter

func IsLetter(b byte) bool

IsLetter checks whether the given byte b is a letter.

func IsLetterLower

func IsLetterLower(b byte) bool

IsLetterLower checks whether the given byte b is in lower case.

func IsLetterUpper

func IsLetterUpper(b byte) bool

IsLetterUpper checks whether the given byte b is in upper case.

func IsNil

func IsNil(value any, traceSource ...bool) bool

IsNil checks whether given <value> is nil. Parameter <traceSource> is used for tracing to the source variable if given <value> is type of a pinter that also points to a pointer. It returns nil if the source is nil when <traceSource> is true. Note that it might use reflect feature which affects performance a little bit.

func IsNotBlank

func IsNotBlank(value string) bool

func IsNumeric

func IsNumeric(s string) bool

IsNumeric checks whether the given string s is numeric. Note that float string like "123.456" is also numeric.

func KebabToCamel added in v1.1.1

func KebabToCamel(str string) string

KebabToCamel 中划线转小驼峰

func Min

func Min[T constraints.Ordered](a, b T) T

func PascalToCamel added in v1.1.1

func PascalToCamel(s string) string

PascalToCamel 大驼峰转小驼峰

func PascalToSnake added in v1.1.1

func PascalToSnake(s string) string

PascalToSnake 大驼峰转蛇形

func ReadDir added in v1.1.1

func ReadDir(dir string) []string

ReadDir 读取目录下的所有文件, 返回文件名列表

func Round added in v1.1.1

func Round(val float64, n int) float64

func RunWithRetry

func RunWithRetry(runFunc func(idx int) (retry bool, err error), maxCnt int) error

RunWithRetry

func SafeGo

func SafeGo(fn func())

SafeGo go with recover

func SanitizeURI added in v1.1.2

func SanitizeURI(u string) string

SanitizeURI takes a URL or URI, removes the domain from it, returns only the URI. This is used for cleaning "next" redirect URLs/URIs to prevent open redirects.

func SnakeToPascal added in v1.1.1

func SnakeToPascal(s string) string

SnakeToPascal 蛇形转大驼峰

func SplitIndex

func SplitIndex(s, sep string, index int) (string, bool)

func ToInt

func ToInt(value string, def ...int) (int, bool)

func ToInt32

func ToInt32(value string, def ...int32) (int32, bool)

func ToInt32D

func ToInt32D(value string, def ...int32) int32

func ToInt64

func ToInt64(value string, def ...int64) (int64, bool)

func ToInt64D

func ToInt64D(value string, def ...int64) int64

func ToIntD

func ToIntD(value string, def ...int) int

func ToString

func ToString(value any) string

func ToStringSlice

func ToStringSlice(val []any) []string

func ToUint

func ToUint(value string, def ...uint) (uint, bool)

func ToUintD

func ToUintD(value string, def ...uint) uint

func Try

func Try(tryFn func(), catchFn func(errString string)) bool

func UcFirst

func UcFirst(s string) string

UcFirst returns a copy of the string s with the first letter mapped to its upper case.

func WaitForSignal

func WaitForSignal()

func WriteFile added in v1.1.2

func WriteFile(filepath string, b []byte) error

WriteFile will write the info on array of bytes b to filepath. It will set the file permission mode to 0660 Returns an error in case there's any.

Types

This section is empty.

Jump to

Keyboard shortcuts

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