Documentation
¶
Overview ¶
Package util provides common utility functions such as MD5, random numbers, path handling, etc.
Index ¶
- Constants
- func Atoa(str interface{}) option.Option[string]
- func Atoi(str interface{}) option.Option[int]
- func Atoui(str interface{}) option.Option[uint]
- func Bytes2String(b []byte) string
- func CheckErr(err error)
- func CheckErrPanic(err error)
- func ExcelSheetNameReplace(fileName string) string
- func FileNameReplace(fileName string) string
- func GetWDPath() string
- func HashString(encode string) uint64
- func IsDirExists(path string) bool
- func IsFileExists(path string) bool
- func IsNum(a string) bool
- func JSONPToJSON(json string) string
- func JSONString(obj interface{}) string
- func KeyinsParse(keyins string) []string
- func MakeHash(s string) string
- func MakeMd5(obj interface{}, length int) string
- func MakeUnique(obj interface{}) string
- func Mkdir(filePath string) result.VoidResult
- func RandomCreateBytes(n int, alphabets ...byte) []byte
- func RelPath(targpath string) (ret result.Result[string])
- func String2Bytes(s string) []byte
- func WalkDir(targpath string, suffixes ...string) (ret result.Result[[]string])
- func WalkFiles(targpath string, suffixes ...string) (ret result.Result[[]string])
- func WalkRelDir(targpath string, suffixes ...string) (ret result.Result[[]string])
- func WalkRelFiles(targpath string, suffixes ...string) (ret result.Result[[]string])
- func XML2MapStr(xmldoc string) map[string]string
Constants ¶
const (
// USE_KEYIN is the initial value for enabling Keyin in Spider.
USE_KEYIN = "\r\t\n"
)
Variables ¶
This section is empty.
Functions ¶
func Bytes2String ¶
Bytes2String converts []byte to string via direct pointer conversion. Both share the same underlying memory; modifying one affects the other. Much faster than string([]byte{}) for large conversions.
func CheckErrPanic ¶
func CheckErrPanic(err error)
func ExcelSheetNameReplace ¶
ExcelSheetNameReplace replaces invalid Excel sheet name characters with underscores.
func FileNameReplace ¶
FileNameReplace replaces invalid filename characters with similar alternatives.
func HashString ¶
func IsDirExists ¶
The IsDirExists judges path is directory or not.
func IsFileExists ¶
The IsFileExists judges path is file or not.
func JSONPToJSON ¶ added in v1.4.0
JSONPToJSON modify jsonp string to json string Example: forbar({a:"1",b:2}) to {"a":"1","b":2}
func JSONString ¶ added in v1.4.0
func JSONString(obj interface{}) string
JSONString converts obj to a JSON string.
func KeyinsParse ¶
KeyinsParse splits user-provided custom keyins into unique tokens.
func MakeUnique ¶
func MakeUnique(obj interface{}) string
MakeUnique creates a unique fingerprint for obj (method 1: FNV-64).
func Mkdir ¶
func Mkdir(filePath string) result.VoidResult
Mkdir creates the directory for the given path.
func RandomCreateBytes ¶
RandomCreateBytes generate random []byte by specify chars.
func String2Bytes ¶
String2Bytes converts string to []byte via direct pointer conversion. Both share the same underlying memory; modifying one affects the other. Do not mutate the returned slice directly (e.g. b[1]='d') or the program may panic.
func WalkRelDir ¶
WalkRelDir walks directories under targpath and returns relative paths, optionally filtered by suffixes.
func WalkRelFiles ¶
WalkRelFiles walks files under targpath and returns relative paths, optionally filtered by suffixes.
func XML2MapStr ¶ added in v1.4.0
XML2MapStr converts simple XML to a string map (supports UTF-8).
Types ¶
This section is empty.