Documentation ¶
Index ¶
- Constants
- Variables
- func AesDecode(encrypted string, k string) (string, error)
- func AesEncode(text string, k string) (string, error)
- func Append(t Transformer, dst, src []byte) (result []byte, n int, err error)
- func Assign[K comparable, V any, Map ~map[K]V](maps ...Map) Map
- func AuthCode(text string, params ...interface{}) string
- func Average[T Float | Integer](collection []T) T
- func Base64Decode(s string) string
- func Base64Encode(s string) string
- func Bytes(t Transformer, b []byte) (result []byte, n int, err error)
- func CeilToFloat[T Float | Integer](x T, n int) float64
- func Chunk[T any, Slice ~[]T](collection Slice, size int) []Slice
- func CliInput(str string, check func(string) error) string
- func CliSelect(question string, choices map[string]string) string
- func CliYesNo(question string) bool
- func ColorHexToRGB(colorHex string) (red, green, blue int)
- func ColorRGBToHex(red, green, blue int) string
- func Comma[T Float | Integer | string](value T, prefixSymbol string) string
- func Compact[T comparable, Slice ~[]T](collection Slice) Slice
- func Concat[T any, Slice ~[]T](collections ...Slice) Slice
- func Contains[T comparable](collection []T, element T) bool
- func CopyDir(srcPath string, dstPath string) error
- func CopyFile(srcPath string, dstPath string) error
- func CountBy[T any](collection []T, predicate func(item T) bool) (count int)
- func CreateDir(absPath string) error
- func CreateFile(path string) bool
- func CurrentPath() string
- func DirSize(path string) (int64, error)
- func DownloadFile(filepath string, url string) error
- func Drop[T any, Slice ~[]T](collection Slice, n int) Slice
- func DropByIndex[T any](collection []T, indexes ...int) []T
- func DropRight[T any, Slice ~[]T](collection Slice, n int) Slice
- func Ellipsis(str string, length uint) string
- func Emoji(s string) (ss string)
- func EmojiDecode(s string) string
- func EmojiEncode(s string) string
- func Empty[T any]() T
- func EncodeUrl(urlStr string) (string, error)
- func Err(err error)
- func FileMode(path string) (fs.FileMode, error)
- func FileSize(path string) (int64, error)
- func FindKey[K comparable, V comparable](object map[K]V, value V) (K, bool)
- func First[T any](collection []T, fallback T) T
- func Flatten[T any, Slice ~[]T](collection []Slice) Slice
- func FloorToFloat[T Float | Integer](x T, n int) float64
- func ForEach[T any](collection []T, iteratee func(item T, index int))
- func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
- func GbkToUtf8(bs []byte) []byte
- func Get(u string) string
- func GetAppPath() string
- func GetDate() string
- func GetDateTime() string
- func GetInternalIp() string
- func GetIps() []string
- func GetMacAddrs() []string
- func GetOsBits() int
- func GetPinyin(s, sp string) (pinyin, shortpinyin string)
- func GetProcessName(pid int) string
- func GetTime() string
- func HasKey[K comparable, V any](in map[K]V, key K) bool
- func Hash(password string, salt ...string) (ps string, err error)
- func HashBytes(password []byte, salt ...[]byte) (hash []byte, err error)
- func HideString(origin string, start, end int, replaceChar string) string
- func ImgToDebase64(path, data string) (ps string)
- func ImgToEnbase64(filename string) (s string)
- func IndexOf[T comparable](collection []T, element T) int
- func Intersect[T comparable, Slice ~[]T](list1 Slice, list2 Slice) Slice
- func Invert[K comparable, V comparable](in map[K]V) map[V]K
- func IsASCII(str string) bool
- func IsBase64(base64 string) bool
- func IsBase64URL(v string) bool
- func IsChinese(s string) bool
- func IsChineseIdNum(id string) bool
- func IsChineseMobile(mobileNum string) bool
- func IsCreditCard(creditCart string) bool
- func IsDir(path string) bool
- func IsEmail(email string) bool
- func IsEmpty[T comparable](v T) bool
- func IsExist(path string) bool
- func IsFloat(v any) bool
- func IsGBK(data []byte) bool
- func IsHex(v string) bool
- func IsInt(v any) bool
- func IsInternalIP(IP net.IP) bool
- func IsIp(ipstr string) bool
- func IsIpV6(ipstr string) bool
- func IsJSON(str string) bool
- func IsJWT(v string) bool
- func IsLeapYear(year int) bool
- func IsLink(path string) bool
- func IsLinux() bool
- func IsMac() bool
- func IsNil(x any) bool
- func IsNumber(v any) bool
- func IsPublicIP(IP net.IP) bool
- func IsString(v any) bool
- func IsStrongPassword(password string, length int) bool
- func IsUrl(str string) bool
- func IsUtf8(s string) bool
- func IsWeakPassword(password string) bool
- func IsWeixin(r *http.Request) bool
- func IsWindows() bool
- func IsZipFile(filepath string) bool
- func Join[T any](slice []T, separator string) string
- func Keys[K comparable, V any](in ...map[K]V) []K
- func Last[T any](collection []T, fallback T) T
- func LastIndexOf[T comparable](collection []T, element T) int
- func ListFileNames(path string) ([]string, error)
- func MTime(filepath string) (int64, error)
- func MapToQueryString(param map[string]any) string
- func MapToSlice[K comparable, V any, R any](in map[K]V, iteratee func(key K, value V) R) []R
- func Match(password, hash string) bool
- func MatchBytes(password []byte, hash []byte) bool
- func Max[T Ordered](collection []T) T
- func Md5(s string) string
- func MiMeType(file any) string
- func Min[T Ordered](collection []T) T
- func Nth[T any, N Integer](collection []T, nth N) (T, error)
- func OpenURL(url string)
- func Openurl(url string)
- func PasswordHash(password string) (string, error)
- func PasswordVerify(password, hash string) bool
- func Percent(val, total float64, n int) float64
- func PickByKeys[K comparable, V any, Map ~map[K]V](in Map, keys []K) Map
- func PickByValues[K comparable, V comparable, Map ~map[K]V](in Map, values []V) Map
- func PointDistance(x1, y1, x2, y2 float64) float64
- func RandColor() string
- func RandInt(min, max int) int
- func RandomSlice[T any, Slice ~[]T](collection Slice, count int) Slice
- func RandomString(size int) string
- func Range[T Integer | Float](start, end, step T) []T
- func ReadCsvFile(filepath string, delimiter ...rune) ([][]string, error)
- func ReadFile(path string) (reader io.ReadCloser, closeFn func(), err error)
- func ReadFileByLine(path string) ([]string, error)
- func ReadFileToString(path string) (string, error)
- func RemoveFile(path string) error
- func Replace[T comparable, Slice ~[]T](collection Slice, old T, new T, n int) Slice
- func Reverse[T any, Slice ~[]T](collection Slice) Slice
- func RoundToFloat[T Float | Integer](x T, n int) float64
- func RoundToString[T Float | Integer](x T, n int) string
- func RuneLength(str string) int
- func Salt(rounds ...int) (string, error)
- func SaltBytes(rounds ...int) (salt []byte, err error)
- func Sha(filepath string, shaType ...int) (string, error)
- func Sha1(str string) string
- func Sha256(str string) string
- func Sha512(str string) string
- func Shuffle[T any, Slice ~[]T](collection Slice) Slice
- func Slice[T any, Slice ~[]T](collection Slice, start int, end int) Slice
- func SliceToMap[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
- func Sort[T Ordered](slice []T, sortOrder ...string)
- func Splice[T any, Slice ~[]T](collection Slice, i int, elements ...T) Slice
- func SplitEx(s, sep string, removeEmptyString bool) []string
- func String(t Transformer, s string) (result string, n int, err error)
- func StripTags(content string) string
- func Subset[T any, Slice ~[]T](collection Slice, offset int, length uint) Slice
- func Substring(s string, offset int, length uint) string
- func Sum[T Float | Integer | Complex](collection []T) T
- func TableToSlice(s string) [][]string
- func Ternary[T any](condition bool, ifOutput T, elseOutput T) T
- func TernaryF[T any](condition bool, ifFunc func() T, elseFunc func() T) T
- func TimeAddDay(t time.Time, day int64) time.Time
- func TimeAddHour(t time.Time, hour int64) time.Time
- func TimeAddMinute(t time.Time, minute int64) time.Time
- func TimeAddYear(t time.Time, year int64) time.Time
- func TimeDaysBetween(start, end time.Time) int
- func TimeLine(t int64) string
- func TimeToStr(t time.Time, format string, timezone ...string) string
- func Times[T any](count int, iteratee func(index int) T) []T
- func Timestamp(timezone ...string) int64
- func TimestampToStr(t int64) string
- func TimestampToTime(t int64) time.Time
- func TimestrToTime(str, format string, timezone ...string) (time.Time, error)
- func TimestrToTimestamp(s string) int64
- func ToAnySlice[T any](collection []T) []any
- func ToBits(s uint64) string
- func ToBool(s string) (bool, error)
- func ToBytes(value any) ([]byte, error)
- func ToChar(s string) []string
- func ToFloat(value any) (float64, error)
- func ToInt(value any) (int64, error)
- func ToJson(value any) (string, error)
- func ToSlice[T any](items ...T) []T
- func ToString(value any) string
- func ToUrlBase64(value any) string
- func Trim(str string, characterMask ...string) string
- func TruncRound[T Float | Integer](x T, n int) T
- func Typeof(a any) reflect.Type
- func UnZip(zipFile string, destPath string) error
- func UnicodeToUtf8(str string) string
- func Union[T comparable, Slice ~[]T](lists ...Slice) Slice
- func Uniq[T comparable, Slice ~[]T](collection Slice) Slice
- func UniqBy[T any, U comparable, Slice ~[]T](collection Slice, iteratee func(item T) U) Slice
- func Uniqid(prefix string) string
- func Utf8ToGbk(bs []byte) []byte
- func Utf8ToUnicode(str string) string
- func ValueOr[K comparable, V any](in map[K]V, key K, fallback V) V
- func Values[K comparable, V any](in ...map[K]V) []V
- func WriteBytesToFile(filepath string, content []byte) error
- func WriteCsvFile(filepath string, records [][]string, append bool, delimiter ...rune) error
- func WriteMapsToCsv(filepath string, records []map[string]any, appendToExistingFile bool, ...) error
- func WriteStringToFile(filepath string, content string, append bool) error
- func Zip(path string, destPath string) error
- func ZipAppendEntry(fpath string, destPath string) error
- type Complex
- type Decoder
- type Encoder
- type Encoding
- type Encoding1
- type Entry
- type Float
- type FuncEncoding
- type Integer
- type Interface
- type MIB
- type Map
- type MapIntAny
- type MapIntInt
- type MapIntStr
- type MapStrAny
- type MapStrInt
- type MapStrStr
- type NopResetter
- type Ordered
- type Reader
- type RepertoireError
- type Signed
- type SimpleEncoding
- type SpanningTransformer
- type Transformer
- type Unsigned
- type Writer
Constants ¶
const ( MaxRounds = 31 MinRounds = 4 DefaultRounds = 12 SaltLen = 16 BlowfishRounds = 16 )
const ASCIISub = '\x1a'
ASCIISub is the ASCII substitute character, as recommended by https://unicode.org/reports/tr36/#Text_Comparison
Variables ¶
var ( InvalidRounds = errors.New("bcrypt: Invalid rounds parameter") InvalidSalt = errors.New("bcrypt: Invalid salt supplied") )
var ( // ErrShortDst means that the destination buffer was too short to // receive all of the transformed bytes. ErrShortDst = errors.New("transform: short destination buffer") // ErrShortSrc means that the source buffer has insufficient data to // complete the transformation. ErrShortSrc = errors.New("transform: short source buffer") // ErrEndOfSpan means that the input and output (the transformed input) // are not identical. ErrEndOfSpan = errors.New("transform: input and output are not identical") )
编码转换
var ( // Discard is a Transformer for which all Transform calls succeed // by consuming all bytes and writing nothing. Discard Transformer = discard{} // Nop is a SpanningTransformer that copies src to dst. Nop SpanningTransformer = nop{} )
var (
DefaultTrimChars = string([]byte{
'\t',
'\v',
'\n',
'\r',
'\f',
' ',
0x00,
0x85,
0xA0,
})
)
var ErrASCIIReplacement = RepertoireError(ASCIISub)
var ErrInvalidUTF8 = errors.New("encoding: invalid UTF-8")
ErrInvalidUTF8 means that a transformer encountered invalid UTF-8.
var UTF8ValidatorTransformer = utf8Validator{}
UTF8Validator is a transformer that returns ErrInvalidUTF8 on the first input byte that is not valid UTF-8.
Functions ¶
func AesDecode ¶ added in v1.2.7
AesDecode
@Description: AES解密 @param encrypted @param k @return string @return error
func AesEncode ¶ added in v1.2.7
AesEncode
@Description: AES加密,支持aes128 192 256 @param text @param k @return string @return error
func Append ¶
func Append(t Transformer, dst, src []byte) (result []byte, n int, err error)
Append appends the result of converting src[:n] using t to dst, where n <= len(src), If err == nil, n will be len(src). It calls Reset on t.
func Assign ¶ added in v1.2.7
func Assign[K comparable, V any, Map ~map[K]V](maps ...Map) Map
Assign[K comparable, V any, Map ~map[K]V]
@Description: 合并map @param maps @return Map
func AuthCode ¶ added in v1.2.7
Authcode("1234==+wo我们",true,"abc")
@Description:对称加密解密 @param text @param params @return string
func Bytes ¶
func Bytes(t Transformer, b []byte) (result []byte, n int, err error)
Bytes returns a new byte slice with the result of converting b[:n] using t, where n <= len(b). If err == nil, n will be len(b). It calls Reset on t.
func CeilToFloat ¶ added in v1.2.7
CeilToFloat[T Float | Integer] CeilToFloat(3.14159, 1)3.2 CeilToFloat(5, 4) 5
@Description: 向上舍入(进一法),保留n位小数 @param x @param n @return float64
func Chunk ¶
Chunk[T any, Slice ~[]T]
@Description: 分割数组 @param collection @param size @return []Slice
func CliInput ¶ added in v1.2.7
CliInput
@Description: cli输入 @param str @param check nil @return string
func CliSelect ¶ added in v1.2.7
CliSelect
@Description: cli选择多项 @param question @param choices @return string
func ColorHexToRGB ¶
ColorHexToRGB
@Description: 十六进制转换rgb @param colorHex @return red @return green @return blue
func ColorRGBToHex ¶
ColorRGBToHex
@Description: rgb转换十六进制 @param red @param green @param blue @return string
func Comma ¶ added in v1.2.7
Comma[T Float | Integer | string]
@Description: 逗号分割数字或字符串,支持添加前缀 @param value @param prefixSymbol @return string
func Compact ¶
func Compact[T comparable, Slice ~[]T](collection Slice) Slice
Compact[T comparable, Slice ~[]T]
@Description: 返回去除 "" nil字符的切片 @param collection @return Slice
func Concat ¶ added in v1.2.7
func Concat[T any, Slice ~[]T](collections ...Slice) Slice
Concat[T any, Slice ~[]T]
@Description: 合并数组并排序 @param collections @return Slice
func Contains ¶ added in v1.2.7
func Contains[T comparable](collection []T, element T) bool
Contains[T comparable]
@Description: 数组中是否包含某元素 @param collection @param element @return bool
func CopyDir ¶ added in v1.2.7
CopyDir
@Description: 复制目录到目标路径 @param srcPath @param dstPath @return error
func CountBy ¶ added in v1.2.7
CountBy[T any]
@Description: 计算符合条件元素数量 @param collection @param predicate @return count
func Drop ¶
Drop[T any, Slice ~[]T]
@Description: slice开头删除元素 @param collection @param n @return Slice
func DropByIndex ¶ added in v1.2.7
DropByIndex[T any]
@Description: 根据索引删除元素 @param collection @param indexes @return []T
func DropRight ¶
DropRight[T any, Slice ~[]T]
@Description: slice末尾删除元素 @param collection @param n @return Slice
func Ellipsis ¶ added in v1.2.7
Ellipsis
@Description: 字符串截取 @param str @param length @return string
func EncodeUrl ¶
EncodeUrl ?a=1&b=[2] -> ?a=1&b=%5B2%5D
@Description: 编码url @param urlStr @return string @return error
func FileMode ¶ added in v1.2.7
FileMode
@Description:获取文件信息 @param path @return fs.FileMode @return error
func FindKey ¶ added in v1.2.7
func FindKey[K comparable, V comparable](object map[K]V, value V) (K, bool)
FindKey[K comparable, V comparable]
@Description: 在map中查找值的键 @param object @param value @return K @return bool
func First ¶ added in v1.2.7
func First[T any](collection []T, fallback T) T
FirstOr[T any]
@Description: 返回集合第一个元素,不存在则是默认值 @param collection @param fallback @return T
func Flatten ¶
func Flatten[T any, Slice ~[]T](collection []Slice) Slice
Flatten[T any, Slice ~[]T]
@Description: 多维数组转换一维 @param collection @return Slice
func FloorToFloat ¶ added in v1.2.7
FloorToFloat[T Float | Integer] FloorToFloat(3.14159, 2) 3.14 FloorToFloat(5, 4) 5
@Description: 向下舍入/去尾法 保留n位 @param x @param n @return float64
func FromEntries ¶ added in v1.2.7
func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
FromEntries[K comparable, V any]
@Description: 键值对数组转换map @param entries @param V] @return map[K]V
func GbkToUtf8 ¶ added in v1.2.7
GbkToUtf8
@Description: gbk转换utf8 @param bs @return []byte @return error
func GetDateTime ¶ added in v1.2.7
func GetDateTime() string
GetDateTime
@Description: 日期时间 @return string
func GetInternalIp ¶ added in v1.2.7
func GetInternalIp() string
GetInternalIp
@Description: 获取内部ipv4 @return string
func GetMacAddrs ¶ added in v1.2.7
func GetMacAddrs() []string
GetMacAddrs
@Description: 获取Mac地址 @return []string
func GetProcessName ¶ added in v1.2.7
GetProcessName
@Description: 根据进程pid返回进程名称,此函数用于win,可以用来判断是否双击打开exe
GetProcessName(os.Getppid()) == "explorer.exe" 是双击 GetProcessName(os.Getpid()) 当前程序名称
@param pid @return string
func HasKey ¶
func HasKey[K comparable, V any](in map[K]V, key K) bool
HasKey[K comparable, V any]
@Description:判断key是否存在 @param in @param key @return bool
func HideString ¶
HideString
@Description:隐藏字符串中某些字符 @param origin @param start 开始 @param end 结束 @param replaceChar 要替换如 * @return string
func ImgToDebase64 ¶ added in v1.2.7
ImgToDebase64
@Description: 图片解码base64成文件 @param path @param data @return ps
func ImgToEnbase64 ¶ added in v1.2.7
ImgToEnbase64
@Description: 图片文件转换成base64字符 @param filename @return s
func IndexOf ¶ added in v1.2.7
func IndexOf[T comparable](collection []T, element T) int
IndexOf[T comparable]
@Description: 元素在数组中首次出现的索引,没有-1 @param collection @param element @return int
func Intersect ¶
func Intersect[T comparable, Slice ~[]T](list1 Slice, list2 Slice) Slice
Intersect[T comparable, Slice ~[]T]
@Description: 计算交集 @param list1 @param list2 @return Slice
func Invert ¶
func Invert[K comparable, V comparable](in map[K]V) map[V]K
Invert[K comparable, V comparable]
@Description: map键值对调 @param in @return map[V]K
func IsChineseMobile ¶ added in v1.2.7
IsChineseMobile check if the string is chinese mobile number.
@Description: 是否手机号 @param mobileNum @return bool
func IsCreditCard ¶ added in v1.2.7
func IsEmpty ¶
func IsEmpty[T comparable](v T) bool
IsEmpty[T comparable]
@Description: 判断是否为空,0,""都是空 @param v @return bool
func IsStrongPassword ¶
IsStrongPassword
@Description: 是否强密码 @param password @param length @return bool
func IsWeakPassword ¶ added in v1.2.7
IsWeakPassword
@Description: 是否弱密码数字或大小写 @param password @return bool
func Join ¶
Join[T any]
@Description: 分隔符链接切片元素,切片转换字符串用分隔符链接 @param slice @param separator @return string
func Keys ¶
func Keys[K comparable, V any](in ...map[K]V) []K
Keys[K comparable, V any]
@Description: 返回map的key组成的切片,去重用Uniq @param in @return []K
func LastIndexOf ¶ added in v1.2.7
func LastIndexOf[T comparable](collection []T, element T) int
LastIndexOf[T comparable]
@Description:数组中找到值的最后一次出现的索引,如果找不到该值,则返回 -1 @param collection @param element @return int
func ListFileNames ¶ added in v1.2.7
ListFileNames
@Description: 返回目录下所有文件名 @param path @return []string @return error
func MapToQueryString ¶ added in v1.2.7
MapToQueryString
var m = map[string]any{ "c": 3, "a": 1, "b": 2, } a=1&b=2&c=3 @Description:map转换成http查询 @param param @return string
func MapToSlice ¶
func MapToSlice[K comparable, V any, R any](in map[K]V, iteratee func(key K, value V) R) []R
MapToSlice[K comparable, V any, R any]
@Description: map转换slice @param in @param iteratee @return []R
func MatchBytes ¶
func Max ¶
func Max[T Ordered](collection []T) T
Max[T Ordered]
@Description: 切片求最大值 @param collection @return T
func MiMeType ¶
MiMeType
@Description: 获取文件mime类型,字符串或*os.File @param file f, _ := os.Open("./file.go") 或"1.txt" @return string
func Min ¶
func Min[T Ordered](collection []T) T
Min[T Ordered]
@Description: 切片求最小值 @param collection @return T
func Nth ¶ added in v1.2.7
Nth[T any, N Integer]
@Description: 返回索引处元素 @param collection @param nth @return T @return error
func OpenURL ¶ added in v1.2.7
func OpenURL(url string)
OpenURL
@Description: 访问URL,用于cli @param url
func PasswordHash ¶
PasswordHash
@Description: 散列密码加密 @param password 密码 @return string 散列密码 @return error
func PasswordVerify ¶
PasswordVerify
@Description: 验证散列密码 @param password 密码 @param hash 散列密码 @return bool
func PickByKeys ¶ added in v1.2.7
func PickByKeys[K comparable, V any, Map ~map[K]V](in Map, keys []K) Map
PickByKeys[K comparable, V any, Map ~map[K]V]
@Description: 根据给定key选取map @param in @param keys @return Map
func PickByValues ¶ added in v1.2.7
func PickByValues[K comparable, V comparable, Map ~map[K]V](in Map, values []V) Map
PickByValues[K comparable, V comparable, Map ~map[K]V]
@Description: 根据值选择map组成的新map @param in @param values @return Map
func PointDistance ¶
PointDistance
@Description: 计算两个坐标距离 @param x1 @param y1 @param x2 @param y2 @return float64
func RandomSlice ¶ added in v1.2.7
RandomSlice[T any, Slice ~[]T]
@Description:数组中随机返回n个元素 @param collection @param count @return Slice
func Range ¶
Range[T Integer | Float]
@Description: 生成数组 @param start @param end @param step 步长 @return []T
func ReadCsvFile ¶
ReadCsvFile
@Description: 读取csv文件 @param filepath @param delimiter @return [][]string @return error
func ReadFile ¶
func ReadFile(path string) (reader io.ReadCloser, closeFn func(), err error)
ReadFile reader, fn, err := fileutil.ReadFile("https://httpbin.org/robots.txt")
if err != nil { return } defer fn() dat, err := io.ReadAll(reader) if err != nil { return } fmt.Println(string(dat)) @Description: 读取文件或URL文件 @param path @return reader @return closeFn @return err
func ReadFileByLine ¶
ReadFileByLine
@Description:按行读取文件内容 @param path @return []string @return error
func ReadFileToString ¶ added in v1.2.7
ReadFileToString
@Description: 读取文件到字符串 @param path @return string @return error
func Replace ¶ added in v1.2.7
func Replace[T comparable, Slice ~[]T](collection Slice, old T, new T, n int) Slice
Replace[T comparable, Slice ~[]T]
@Description: 替换元素 @param collection @param old @param new @param n -1是全部替换 @return Slice
func Reverse ¶
func Reverse[T any, Slice ~[]T](collection Slice) Slice
Reverse[T any, Slice ~[]T]
@Description: 反序数组 @param collection @return Slice
func RoundToFloat ¶
RoundToFloat[T Float | Integer]
@Description: 四舍五入返回 float64 @param x @param n 保留小数位数 @return float64
func RoundToString ¶
RoundToString[T Float | Integer]
@Description: 四舍五入到字符串 @param x @param n @return string
func Sha ¶ added in v1.2.7
Sha
@Description: 返回文件sha值,参数`shaType` 应传值为: 1, 256,512 @param filepath @param shaType @return string @return error
func Shuffle ¶
func Shuffle[T any, Slice ~[]T](collection Slice) Slice
Shuffle[T any, Slice ~[]T]
@Description: 洗牌打乱数组 @param collection @return Slice
func Slice ¶ added in v1.2.7
Slice[T any, Slice ~[]T]
@Description: 截取切片,不包括结尾索引 @param collection @param start @param end @return Slice
func SliceToMap ¶
func SliceToMap[T any, K comparable, V any](collection []T, transform func(item T) (K, V)) map[K]V
SliceToMap[T any, K comparable, V any]
@Description: slice转换map @param collection @param transform @return map[K]V
func Splice ¶ added in v1.2.7
Splice[T any, Slice ~[]T]
@Description: 在索引处插入多个值 @param collection @param i @param elements @return Slice
func SplitEx ¶ added in v1.2.7
SplitEx
@Description: 字符串分割为切片 @param s @param sep 分隔符号 @param removeEmptyString 是否移除空字符串 @return []string
func String ¶
func String(t Transformer, s string) (result string, n int, err error)
String returns a string with the result of converting s[:n] using t, where n <= len(s). If err == nil, n will be len(s). It calls Reset on t.
func Subset ¶ added in v1.2.7
Subset[T any, Slice ~[]T]
@Description: slice截取 @param collection @param offset 开始 @param length 长度 @return Slice
func Substring ¶
Substring[T ~string]
@Description: 子字符串截取 @param str @param offset @param length @return T
func TableToSlice ¶ added in v1.2.7
TableToSlice
@Description: html表格转换切片,去除html标签 @param s @return [][]string
func Ternary ¶
Ternary[T any]
@Description:三元运算,相当于if-else,是语句 @param condition @param ifOutput @param elseOutput @return T
func TernaryF ¶
TernaryF[T any]
@Description: 三元运算,是函数 @param condition @param ifFunc @param elseFunc @return T
func TimeAddDay ¶ added in v1.2.7
TimeAddDay
@Description: 加减日期,实现昨天明天 @param t @param day @return time.Time
func TimeAddHour ¶ added in v1.2.7
TimeAddHour add or sub hour to the time.
@Description: 添加减少小时 @param t @param hour @return time.Time
func TimeAddMinute ¶ added in v1.2.7
TimeAddMinute
@Description: 添加减少分钟 @param t @param minute @return time.Time
func TimeAddYear ¶ added in v1.2.7
TimeAddYear
@Description: 添加减少年 @param t @param year @return time.Time
func TimeDaysBetween ¶ added in v1.2.7
TimeDaysBetween
@Description: 日期之间天数差 @param start @param end @return int
func TimeToStr ¶ added in v1.2.7
TimeToStr
@Description: 时间转换字符串格式化 @param t @param format @param timezone @return string
func Times ¶ added in v1.2.7
Times[T any]
@Description: 调用多次迭代 @param count @param iteratee @return []T
func TimestampToStr ¶ added in v1.2.7
TimestampToStr
@Description: 时间戳转换时间字符串 @param t @return string
func TimestampToTime ¶ added in v1.2.7
TimestampToTime
@Description: 时间戳转换go时间 @param t @return time.Time
func TimestrToTime ¶ added in v1.2.7
TimestrToTime
@Description: 字符串转换go时间格式 @param str @param format @param timezone @return time.Time @return error
func TimestrToTimestamp ¶ added in v1.2.7
TimestrToTimestamp
@Description: 时间字符串转换时间戳 @param s @return int64
func ToAnySlice ¶ added in v1.2.7
ToAnySlice[T any]
@Description: 转换成any类型切片 @param collection @return []any
func ToSlice ¶ added in v1.2.7
func ToSlice[T any](items ...T) []T
ToSlice[T any]
@Description: 字符转换成切片 @param items @return []T
func ToUrlBase64 ¶ added in v1.2.7
ToUrlBase64
@Description: 转换成urlbase64 @param value @return string
func TruncRound ¶
TruncRound[T Float | Integer]
@Description: 截断n位小数不四舍五入 @param x @param n @return T
func UnicodeToUtf8 ¶ added in v1.2.7
UnicodeToUtf8 @Description: unicode转换utf8 @param str @return string utf8
func Union ¶
func Union[T comparable, Slice ~[]T](lists ...Slice) Slice
Union[T comparable, Slice ~[]T]
@Description: 并集 @param lists @return Slice
func Uniq ¶
func Uniq[T comparable, Slice ~[]T](collection Slice) Slice
Uniq[T comparable, Slice ~[]T]
@Description:返回数组的无重复版本 @param collection @return Slice
func UniqBy ¶ added in v1.2.7
func UniqBy[T any, U comparable, Slice ~[]T](collection Slice, iteratee func(item T) U) Slice
UniqBy[T any, U comparable, Slice ~[]T]
@Description: 返回无重复数组处理后结果 @param collection @param iteratee @return Slice
func Utf8ToGbk ¶ added in v1.2.7
Utf8ToGbk
@Description: uft8转gbk @param bs @return []byte @return error
func Utf8ToUnicode ¶ added in v1.2.7
Utf8ToUnicode
@Description: uft8转换unicode @param str @return string
func ValueOr ¶ added in v1.2.7
func ValueOr[K comparable, V any](in map[K]V, key K, fallback V) V
ValueOr[K comparable, V any]
@Description: 根据key返回map值,不存在返回默认值 @param in @param key @param fallback 默认值 @return V
func Values ¶
func Values[K comparable, V any](in ...map[K]V) []V
Values[K comparable, V any]
@Description: 返回map的val组成的新切片 @param in @return []V
func WriteBytesToFile ¶ added in v1.2.7
WriteBytesToFile
@Description: bytes写入文件 @param filepath @param content @return error
func WriteCsvFile ¶
WriteCsvFile
data := [][]string{ {"Lili", "22", "female"}, {"Jim", "21", "male"}, } @Description: 写入csv文件 @param filepath @param records @param append 是否追加 @param delimiter @return error
func WriteMapsToCsv ¶ added in v1.2.7
func WriteMapsToCsv(filepath string, records []map[string]any, appendToExistingFile bool, delimiter rune, headers ...[]string) error
WriteMapsToCsv
@Description: 将map切片写入csv文件中 @param filepath @param records []map[string]any{ {"Name": "Lili", "Age": "22", "Gender": "female"}, {"Name": "Jim", "Age": "21", "Gender": "male"}, } @param appendToExistingFile 是否追加 @param delimiter 分隔符号 ; @param headers []string{"Name", "Age", "Gender"} @return error
func WriteStringToFile ¶ added in v1.2.7
WriteStringToFile
@Description: 写字符串到文件 @param filepath @param content @param append @return error
func ZipAppendEntry ¶
ZipAppendEntry
@Description: 通过将单个文件或目录追加到现有的zip文件 @param fpath @param destPath @return error
Types ¶
type Complex ¶
type Complex interface { ~complex64 | ~complex128 }
type Decoder ¶
type Decoder struct { Transformer // contains filtered or unexported fields }
A Decoder converts bytes to UTF-8. It implementsTransformer.
Transforming source bytes that are not of that encoding will not result in an error per se. Each byte that cannot be transcoded will be represented in the output by the UTF-8 encoding of '\uFFFD', the replacement rune.
func (*Decoder) Bytes ¶
Bytes converts the given encoded bytes to UTF-8. It returns the converted bytes or nil, err if any error occurred.
type Encoder ¶
type Encoder struct { Transformer // contains filtered or unexported fields }
An Encoder converts bytes from UTF-8. It implementsTransformer.
Each rune that cannot be transcoded will result in an error. In this case, the transform will consume all source byte up to, not including the offending rune. Transforming source bytes that are not valid UTF-8 will be replaced by `\uFFFD`. To return early with an error instead, useChain to preprocess the data with a UTF8Validator.
func HTMLEscapeUnsupported ¶
HTMLEscapeUnsupported wraps encoders to replace source runes outside the repertoire of the destination encoding with HTML escape sequences.
This wrapper exists to comply to URL and HTML forms requiring a non-terminating legacy encoder. The produced sequences may lead to data loss as they are indistinguishable from legitimate input. To avoid this issue, use UTF-8 encodings whenever possible.
func ReplaceUnsupported ¶
ReplaceUnsupported wraps encoders to replace source runes outside the repertoire of the destination encoding with an encoding-specific replacement.
This wrapper is only provided for backwards compatibility and legacy handling. Its use is strongly discouraged. Use UTF-8 whenever possible.
func (*Encoder) Bytes ¶
Bytes converts bytes from UTF-8. It returns the converted bytes or nil, err if any error occurred.
type Encoding ¶
type Encoding interface { // NewDecoder returns a Decoder. NewDecoder() *Decoder // NewEncoder returns an Encoder. NewEncoder() *Encoder }
第二波
var (
GBK Encoding = &gbk
)
var Replacement Encoding = replacement{}
Replacement is the replacement encoding. Decoding from the replacement encoding yields a single '\uFFFD' replacement rune. Encoding from UTF-8 to the replacement encoding yields the same as the source bytes except that invalid UTF-8 is converted to '\uFFFD'.
It is defined at http://encoding.spec.whatwg.org/#replacement
type Entry ¶ added in v1.2.7
type Entry[K comparable, V any] struct { Key K Value V }
func Entries ¶ added in v1.2.7
func Entries[K comparable, V any](in map[K]V) []Entry[K, V]
Entries[K comparable, V any]
@Description: map键值对转换数组 @param in @return []Entry[K @return V]
type FuncEncoding ¶
type FuncEncoding struct { Decoder func() Transformer Encoder func() Transformer }
FuncEncoding is an Encoding that combines two functions returning a new Transformer.
func (FuncEncoding) NewDecoder ¶
func (e FuncEncoding) NewDecoder() *Decoder
func (FuncEncoding) NewEncoder ¶
func (e FuncEncoding) NewEncoder() *Encoder
type Interface ¶
type Interface interface { // ID returns an encoding identifier. Exactly one of the mib and other // values should be non-zero. // // In the usual case it is only necessary to indicate the MIB code. The // other string can be used to specify encodings for which there is no MIB, // such as "x-mac-dingbat". // // The other string may only contain the characters a-z, A-Z, 0-9, - and _. ID() (mib MIB, other string) }
----------------------------------
type MIB ¶
type MIB uint16
A MIB identifies an encoding. It is derived from the IANA MIB codes and adds some identifiers for some encodings that are not covered by the IANA standard.
type NopResetter ¶
type NopResetter struct{}
NopResetter can be embedded by implementations of Transformer to add a nop Reset method.
func (NopResetter) Reset ¶
func (NopResetter) Reset()
Reset implements the Reset method of the Transformer interface.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader wraps another io.Reader by transforming the bytes read.
type RepertoireError ¶
type RepertoireError byte
A RepertoireError indicates a rune is not in the repertoire of a destination encoding. It is associated with an encoding-specific suggested replacement byte.
func (RepertoireError) Error ¶
func (r RepertoireError) Error() string
Error implements the error interrface.
func (RepertoireError) Replacement ¶
func (r RepertoireError) Replacement() byte
Replacement returns the replacement string associated with this error.
type SimpleEncoding ¶
type SimpleEncoding struct { Decoder Transformer Encoder Transformer }
SimpleEncoding is an Encoding that combines two Transformers.
func (*SimpleEncoding) NewDecoder ¶
func (e *SimpleEncoding) NewDecoder() *Decoder
func (*SimpleEncoding) NewEncoder ¶
func (e *SimpleEncoding) NewEncoder() *Encoder
type SpanningTransformer ¶
type SpanningTransformer interface { Transformer // Span returns a position in src such that transforming src[:n] results in // identical output src[:n] for these bytes. It does not necessarily return // the largest such n. The atEOF argument tells whether src represents the // last bytes of the input. // // Callers should always account for the n bytes consumed before // considering the error err. // // A nil error means that all input bytes are known to be identical to the // output produced by the Transformer. A nil error can be returned // regardless of whether atEOF is true. If err is nil, then n must // equal len(src); the converse is not necessarily true. // // ErrEndOfSpan means that the Transformer output may differ from the // input after n bytes. Note that n may be len(src), meaning that the output // would contain additional bytes after otherwise identical output. // ErrShortSrc means that src had insufficient data to determine whether the // remaining bytes would change. Other than the error conditions listed // here, implementations are free to report other errors that arise. // // Calling Span can modify the Transformer state as a side effect. In // effect, it does the transformation just as calling Transform would, only // without copying to a destination buffer and only up to a point it can // determine the input and output bytes are the same. This is obviously more // limited than calling Transform, but can be more efficient in terms of // copying and allocating buffers. Calls to Span and Transform may be // interleaved. Span(src []byte, atEOF bool) (n int, err error) }
SpanningTransformer extends the Transformer interface with a Span method that determines how much of the input already conforms to the Transformer.
type Transformer ¶
type Transformer interface { // Transform writes to dst the transformed bytes read from src, and // returns the number of dst bytes written and src bytes read. The // atEOF argument tells whether src represents the last bytes of the // input. // // Callers should always process the nDst bytes produced and account // for the nSrc bytes consumed before considering the error err. // // A nil error means that all of the transformed bytes (whether freshly // transformed from src or left over from previous Transform calls) // were written to dst. A nil error can be returned regardless of // whether atEOF is true. If err is nil then nSrc must equal len(src); // the converse is not necessarily true. // // ErrShortDst means that dst was too short to receive all of the // transformed bytes. ErrShortSrc means that src had insufficient data // to complete the transformation. If both conditions apply, then // either error may be returned. Other than the error conditions listed // here, implementations are free to report other errors that arise. Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) // Reset resets the state and allows a Transformer to be reused. Reset() }
Transformer transforms bytes.
func Chain ¶
func Chain(t ...Transformer) Transformer
Chain returns a Transformer that applies t in sequence.
func RemoveFunc
deprecated
func RemoveFunc(f func(r rune) bool) Transformer
Deprecated: Use runes.Remove instead.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer wraps another io.Writer by transforming the bytes read. The user needs to call Close to flush unwritten bytes that may be buffered.