Documentation ¶
Index ¶
- Constants
- Variables
- func AddBytes32(h uint32, b []byte) uint32
- func AddBytes64(h uint64, b []byte) uint64
- func AddString(s ...string) string
- func AddString32(h uint32, s string) uint32
- func AddString64(h uint64, s string) uint64
- func AddStringBytes(s ...string) []byte
- func AddUint32(h, u uint32) uint32
- func AddUint64(h uint64, u uint64) uint64
- func AssertEqual(tb testing.TB, expected, actual interface{}, description ...string)
- func AssertEqualf(tb testing.TB, expected, actual interface{}, description string, ...)
- func AssertPanics(t *testing.T, title string, f func())
- func B2S(b []byte) string
- func B64Decode(s string) []byte
- func B64Encode(b []byte) string
- func B64UrlDecode(s string) []byte
- func B64UrlEncode(b []byte) string
- func BeginOfDay(t time.Time) time.Time
- func BeginOfHour(t time.Time) time.Time
- func BeginOfLastMonth(t time.Time) time.Time
- func BeginOfLastWeek(t time.Time) time.Time
- func BeginOfMinute(t time.Time) time.Time
- func BeginOfMonth(t time.Time) time.Time
- func BeginOfNextMonth(t time.Time) time.Time
- func BeginOfNextWeek(t time.Time) time.Time
- func BeginOfTomorrow(t time.Time) time.Time
- func BeginOfWeek(t time.Time) time.Time
- func BeginOfYear(t time.Time) time.Time
- func BeginOfYesterday(t time.Time) time.Time
- func BigComma(b *big.Int) string
- func BigCommaf(v *big.Float) string
- func Bigoom(n, b *big.Int) (float64, int)
- func CPUTicks() int64
- func CallPath() string
- func Comma(v int64) string
- func Commaf(v float64) string
- func Commai(v int) string
- func Commau(v uint64) string
- func CopyB2S(b []byte) string
- func CopyBytes(b []byte) []byte
- func CopyS2B(s string) []byte
- func CopyString(s string) string
- func CutBytes(s, sep []byte) (before, after []byte, found bool)
- func CutString(s, sep string) (before, after string, found bool)
- func Djb33(s string) uint32
- func EncodeUUID(id []byte) []byte
- func EndOfDay(t time.Time) time.Time
- func EndOfHour(t time.Time) time.Time
- func EndOfLastMonth(t time.Time) time.Time
- func EndOfLastWeek(t time.Time) time.Time
- func EndOfMinute(t time.Time) time.Time
- func EndOfMonth(t time.Time) time.Time
- func EndOfNextMonth(t time.Time) time.Time
- func EndOfNextWeek(t time.Time) time.Time
- func EndOfTomorrow(t time.Time) time.Time
- func EndOfWeek(t time.Time) time.Time
- func EndOfYear(t time.Time) time.Time
- func EndOfYesterday(t time.Time) time.Time
- func EqualFold(b, s string) bool
- func EqualFoldBytes(b, s []byte) bool
- func Executable(evalSymlinks ...bool) string
- func ExecutableDir(evalSymlinks ...bool) string
- func FastIntn(n int) int
- func FastRand() uint32
- func FastRandBytes(n int) []byte
- func FastRandn(n uint32) uint32
- func FnvHash(s string) uint64
- func FnvHash32(s string) uint32
- func GetBytes(v interface{}, defaultVal ...[]byte) []byte
- func GetIPPort(addr net.Addr) (ip net.IP, port int, err error)
- func GetInt(v interface{}, defaultInt ...int) int
- func GetMonthDays(t time.Time) int
- func GetNotInternalIPv4(ip, defaultIP net.IP, flag ...bool) net.IP
- func GetNotInternalIPv4String(ip, defaultIP string, flag ...bool) string
- func GetSafeB2S(b []byte, defaultVal ...string) string
- func GetSafeBytes(b []byte, defaultVal ...[]byte) []byte
- func GetSafeS2B(s string, defaultVal ...[]byte) []byte
- func GetSafeString(s string, defaultVal ...string) string
- func GetString(v interface{}, defaultVal ...string) string
- func Gzip(data []byte) ([]byte, error)
- func GzipLevel(data []byte, level int) (dst []byte, err error)
- func Hash(b []byte, h hash.Hash) []byte
- func HashBytes(b ...[]byte) string
- func HashBytes32(b ...[]byte) uint32
- func HashBytes64(b ...[]byte) uint64
- func HashString(s ...string) string
- func HashString32(s ...string) uint32
- func HashString64(s ...string) uint64
- func HashUint32(u uint32) uint32
- func HashUint64(u uint64) uint64
- func Hmac(b []byte, key []byte, h func() hash.Hash) []byte
- func HmacSHA1(b, key []byte) []byte
- func HmacSHA1Hex(s, key string) string
- func HmacSHA256(b, key []byte) []byte
- func HmacSHA256Hex(s, key string) string
- func HmacSHA512(b, key []byte) []byte
- func HmacSHA512Hex(s, key string) string
- func HumanBaseBytes(v uint64, base float64, sizes []string) string
- func HumanBigBytes(s *big.Int) string
- func HumanBigIBytes(s *big.Int) string
- func HumanBigKbps(s *big.Int) string
- func HumanBytes(v uint64) string
- func HumanGBMB(v uint64) string
- func HumanIBytes(v uint64) string
- func HumanIntBytes(v int) string
- func HumanIntIBytes(v int) string
- func HumanIntKbps(v int) string
- func HumanKbps(v uint64) string
- func ID() uint64
- func IPv42Long(ip net.IP) int
- func IPv4String2Long(ip string) int
- func InIPNet(ip net.IP, ipNets map[*net.IPNet]struct{}) bool
- func InIPNetString(ip string, ipNets map[*net.IPNet]struct{}) bool
- func InInts(slice []int, n int) bool
- func InStrings(ss []string, s string) bool
- func IsDir(s string) bool
- func IsExist(s string) bool
- func IsFile(s string) bool
- func IsIP(ip string) bool
- func IsIPv4(ip string) bool
- func IsIPv6(ip string) bool
- func IsInternalIPv4(ip net.IP) bool
- func IsInternalIPv4String(ip string) bool
- func IsNil(i interface{}) bool
- func IsPrivateIP(ip net.IP) bool
- func IsPrivateIPString(ip string) bool
- func JoinBytes(b ...[]byte) []byte
- func LeftPad(s, pad string, n int) string
- func LeftPadBytes(b, pad []byte, n int) []byte
- func Logn(n, b float64) float64
- func Long2IPv4(n int) net.IP
- func Long2IPv4String(n int) string
- func MD5(b []byte) []byte
- func MD5BytesHex(bs []byte) string
- func MD5Hex(s string) string
- func MD5Reader(r io.Reader) (string, error)
- func MD5Sum(filename string) (string, error)
- func MaxInt(a, b int) int
- func MemHash(s string) uint64
- func MemHash32(s string) uint32
- func MemHashb(b []byte) uint64
- func MemHashb32(b []byte) uint32
- func MinInt(a, b int) int
- func MustBool(v interface{}) bool
- func MustInt(v interface{}) int
- func MustJSON(v interface{}) []byte
- func MustJSONIndent(v interface{}) []byte
- func MustJSONIndentString(v interface{}) string
- func MustJSONString(v interface{}) string
- func MustMD5Sum(filename string) string
- func MustParseHumanBigBytes(s string, defaultVal ...*big.Int) *big.Int
- func MustParseHumanBytes(s string, defaultVal ...uint64) uint64
- func MustString(v interface{}, timeLayout ...string) string
- func NanoTime() int64
- func NewRand(seed ...int64) *rand.Rand
- func Pad(s, pad string, n int) string
- func PadBytes(s, pad []byte, n int) []byte
- func ParseHumanBigBytes(s string) (*big.Int, error)
- func ParseHumanBytes(s string) (uint64, error)
- func ParseIPv4(ip string) net.IP
- func ParseIPv6(ip string) net.IP
- func RandBytes(n int) []byte
- func RandHex(nHalf int) string
- func RandInt(min, max int) int
- func RandString(n int) string
- func RandUint32(min, max uint32) uint32
- func RemoveString(ss []string, s string) ([]string, bool)
- func ReplaceHost(a, b string) string
- func RightPad(s, pad string, n int) string
- func RightPadBytes(b, pad []byte, n int) []byte
- func Round(v float64, precision int) float64
- func RunPath() string
- func S2B(s string) []byte
- func SearchInt(slice []int, n int) int
- func SearchString(ss []string, s string) int
- func Sha1(b []byte) []byte
- func Sha1Hex(s string) string
- func Sha256(b []byte) []byte
- func Sha256Hex(s string) string
- func Sha512(b []byte) []byte
- func Sha512Hex(s string) string
- func SplitHostPort(hostPort string) (host, port string)
- func Str2Bytes(s string) (b []byte)
- func StrToBytes(s string) []byte
- func String2Bytes(s string) (bs []byte)
- func StringToBytes(s string) (b []byte)
- func Sum32(s string) uint32
- func Sum64(s string) uint64
- func SumBytes32(bs []byte) uint32
- func SumBytes64(bs []byte) uint64
- func SumInt(v ...int) int
- func ToLower(b string) string
- func ToLowerBytes(b []byte) []byte
- func ToUpper(b string) string
- func ToUpperBytes(b []byte) []byte
- func Trim(s string, cutset byte) string
- func TrimBytes(b []byte, cutset byte) []byte
- func TrimLeft(s string, cutset byte) string
- func TrimLeftBytes(b []byte, cutset byte) []byte
- func TrimRight(s string, cutset byte) string
- func TrimRightBytes(b []byte, cutset byte) []byte
- func UUID() []byte
- func UUIDShort() string
- func UUIDSimple() string
- func UUIDString() string
- func Ungzip(data []byte) (src []byte, err error)
- func Unzip(data []byte) (src []byte, err error)
- func ValidOptionalPort(port string) bool
- func WaitNextMinute(t ...time.Time)
- func Zip(data []byte) ([]byte, error)
- func ZipLevel(data []byte, level int) (dst []byte, err error)
- type Bool
- func (x *Bool) CAS(old, new bool) bool
- func (x *Bool) CompareAndSwap(old, new bool) (swapped bool)
- func (x *Bool) Load() bool
- func (x *Bool) MarshalJSON() ([]byte, error)
- func (x *Bool) Store(val bool)
- func (x *Bool) StoreFalse()
- func (x *Bool) StoreTrue()
- func (x *Bool) String() string
- func (x *Bool) Swap(new bool) (old bool)
- func (x *Bool) Toggle() (old bool)
- func (x *Bool) UnmarshalJSON(b []byte) error
- type NoCmp
- type NoCopy
Constants ¶
const ( Byte = 1 << (iota * 10) KiByte MiByte GiByte TiByte PiByte EiByte )
Ref: dustin/go-humanize IEC Sizes. kibis of bits
const ( IByte = 1 KByte = IByte * 1000 MByte = KByte * 1000 GByte = MByte * 1000 TByte = GByte * 1000 PByte = TByte * 1000 EByte = PByte * 1000 )
SI Sizes.
Variables ¶
var ( // BigByte is one byte in bit.Ints BigByte = big.NewInt(1) // BigKiByte is 1,024 bytes in bit.Ints BigKiByte = (&big.Int{}).Mul(BigByte, bigIECExp) // BigMiByte is 1,024 k bytes in bit.Ints BigMiByte = (&big.Int{}).Mul(BigKiByte, bigIECExp) // BigGiByte is 1,024 m bytes in bit.Ints BigGiByte = (&big.Int{}).Mul(BigMiByte, bigIECExp) // BigTiByte is 1,024 g bytes in bit.Ints BigTiByte = (&big.Int{}).Mul(BigGiByte, bigIECExp) // BigPiByte is 1,024 t bytes in bit.Ints BigPiByte = (&big.Int{}).Mul(BigTiByte, bigIECExp) // BigEiByte is 1,024 p bytes in bit.Ints BigEiByte = (&big.Int{}).Mul(BigPiByte, bigIECExp) // BigZiByte is 1,024 e bytes in bit.Ints BigZiByte = (&big.Int{}).Mul(BigEiByte, bigIECExp) // BigYiByte is 1,024 z bytes in bit.Ints BigYiByte = (&big.Int{}).Mul(BigZiByte, bigIECExp) )
Ref: dustin/go-humanize
var ( // BigSIByte is one SI byte in big.Ints BigSIByte = big.NewInt(1) // BigKByte is 1,000 SI bytes in big.Ints BigKByte = (&big.Int{}).Mul(BigSIByte, bigSIExp) // BigMByte is 1,000 SI k bytes in big.Ints BigMByte = (&big.Int{}).Mul(BigKByte, bigSIExp) // BigGByte is 1,000 SI m bytes in big.Ints BigGByte = (&big.Int{}).Mul(BigMByte, bigSIExp) // BigTByte is 1,000 SI g bytes in big.Ints BigTByte = (&big.Int{}).Mul(BigGByte, bigSIExp) // BigPByte is 1,000 SI t bytes in big.Ints BigPByte = (&big.Int{}).Mul(BigTByte, bigSIExp) // BigEByte is 1,000 SI p bytes in big.Ints BigEByte = (&big.Int{}).Mul(BigPByte, bigSIExp) // BigZByte is 1,000 SI e bytes in big.Ints BigZByte = (&big.Int{}).Mul(BigEByte, bigSIExp) // BigYByte is 1,000 SI z bytes in big.Ints BigYByte = (&big.Int{}).Mul(BigZByte, bigSIExp) )
var ( // Rand goroutine-safe, use Rand.xxx instead of rand.xxx Rand = NewRand() Seed = FastRand() )
Functions ¶
func AddBytes32 ¶ added in v0.7.0
AddBytes32 adds the hash of b to the precomputed hash value h. Ref: segmentio/fasthash
func AddBytes64 ¶ added in v0.7.0
AddBytes64 adds the hash of b to the precomputed hash value h. Ref: segmentio/fasthash
func AddString32 ¶ added in v0.7.0
AddString32 adds the hash of s to the precomputed hash value h. Ref: segmentio/fasthash
func AddString64 ¶ added in v0.7.0
AddString64 adds the hash of s to the precomputed hash value h. Ref: segmentio/fasthash
func AddStringBytes ¶
AddStringBytes 拼接字符串, 返回 bytes from bytes.Join()
func AddUint32 ¶ added in v0.7.0
AddUint32 adds the hash value of the 8 bytes of u to h. Ref: segmentio/fasthash
func AddUint64 ¶ added in v0.7.0
AddUint64 adds the hash value of the 8 bytes of u to h. Ref: segmentio/fasthash
func AssertEqual ¶
AssertEqual checks if values are equal Ref: gofiber/utils
func AssertEqualf ¶ added in v0.5.2
func B64UrlEncode ¶
B64UrlEncode Base64 解码, 安全 URL, 替换: "+/" 为 "-_"
func BeginOfLastMonth ¶ added in v0.4.0
BeginOfLastMonth 上月第一天 0 点
func BeginOfLastWeek ¶ added in v0.4.0
BeginOfLastWeek 上周一 0 点
func BeginOfNextMonth ¶ added in v0.4.0
BeginOfNextMonth 下月第一天 0 点
func BeginOfNextWeek ¶ added in v0.4.0
BeginOfNextWeek 下周一 0 点
func BeginOfTomorrow ¶ added in v0.4.0
BeginOfTomorrow 明天 0 点
func BeginOfYesterday ¶ added in v0.4.0
BeginOfYesterday 昨天 0 点
func CallPath ¶
func CallPath() string
CallPath 运行时路径, 编译目录 假如: mklink E:\tmp\linkapp.exe D:\Fufu\Test\abc\app.exe 执行: E:\tmp\linkapp.exe CallPath: E:\Go\src\github.com\fufuok\utils\tmp\osext
func Comma ¶ added in v0.1.3
Comma 整数转千分位分隔字符串 Ref: dustin/go-humanize e.g. Comma(834142) -> 834,142
func Commaf ¶ added in v0.1.3
Commaf 浮点数转千分位分隔字符串 Ref: dustin/go-humanize e.g. Commaf(834142.32) -> 834,142.32
func CopyString ¶
CopyString Immutable, string to string e.g. fiberParam := utils.CopyString(c.Params("test")) e.g. utils.CopyString(s[500:1000]) // 可以让 s 被 GC 回收 strings.Clone(s) // go1.18
func CutBytes ¶ added in v0.5.0
CutBytes slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, nil, false.
Cut returns slices of the original slice s, not copies. Ref: go1.18
func CutString ¶ added in v0.5.0
CutString slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, "", false. Ref: go1.18
func Djb33 ¶ added in v0.3.3
Djb33 比 FnvHash32 更快的获取字符串哈希值 djb2 with better shuffling. 5x faster than FNV with the hash.Hash overhead. Ref: patrickmn/go-cache
func EndOfLastMonth ¶ added in v0.4.0
EndOfLastMonth 上月最后一刻
func EndOfLastWeek ¶ added in v0.4.0
EndOfLastWeek 上周一最后一刻
func EndOfNextMonth ¶ added in v0.4.0
EndOfNextMonth 下月最后一刻
func EndOfNextWeek ¶ added in v0.4.0
EndOfNextWeek 下周一最后一刻
func EndOfYesterday ¶ added in v0.4.0
EndOfYesterday 昨天最后时刻
func EqualFold ¶ added in v0.3.2
EqualFold tests ascii strings for equality case-insensitively Ref: fiber
func EqualFoldBytes ¶ added in v0.3.2
EqualFoldBytes tests ascii slices for equality case-insensitively Ref: fiber
func Executable ¶ added in v0.1.2
Executable 当前执行程序绝对路径 true 时返回解析符号链接后的绝对路径 Excutable: E:\tmp\linkapp.exe Excutable(true): D:\Fufu\Test\abc\app.exe
func ExecutableDir ¶ added in v0.1.2
ExecutableDir 当前执行程序所在目录 true 时返回解析符号链接后的目录 ExcutableDir: E:\tmp ExcutableDir(true): D:\Fufu\Test\abc
func FastIntn ¶ added in v0.3.3
FastIntn this is similar to rand.Intn, but faster. A non-negative pseudo-random number in the half-open interval [0,n). Return 0 if n <= 0.
func FastRandBytes ¶ added in v0.3.3
FastRandBytes random bytes, but faster.
func FastRandn ¶ added in v0.3.3
FastRandn 等同于 FastRand() % n, 但更快 See https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
func GetNotInternalIPv4 ¶ added in v0.1.5
GetNotInternalIPv4 如果是内网 IPv4 则使用默认值, flag 为真是必定返回一个 IP
func GetNotInternalIPv4String ¶ added in v0.1.5
GetNotInternalIPv4String 如果是内网 IPv4 则使用默认值
func GetSafeB2S ¶ added in v0.1.1
GetSafeB2S Immutable, 可选指定默认值
func GetSafeBytes ¶ added in v0.1.1
GetSafeBytes Immutable, 可选指定默认值
func GetSafeS2B ¶ added in v0.1.1
GetSafeS2B Immutable, 可选指定默认值
func GetSafeString ¶ added in v0.1.1
GetSafeString Immutable, 可选指定默认值
func HashBytes32 ¶ added in v0.7.0
func HashBytes64 ¶ added in v0.7.0
func HashString32 ¶ added in v0.7.0
func HashString64 ¶ added in v0.7.0
func HashUint32 ¶ added in v0.7.0
HashUint32 returns the hash of u. Ref: segmentio/fasthash
func HashUint64 ¶ added in v0.7.0
HashUint64 returns the hash of u. Ref: segmentio/fasthash
func HmacSHA1Hex ¶
func HmacSHA256 ¶
func HmacSHA256Hex ¶
func HmacSHA512 ¶
func HmacSHA512Hex ¶
func HumanBaseBytes ¶ added in v0.1.3
HumanBaseBytes 数字的数量级表示
func HumanBigBytes ¶ added in v0.1.11
HumanBigBytes produces a human readable representation of an SI size.
See also: ParseHumanBigBytes.
HumanBigBytes(82854982) -> 83 MB
func HumanBigIBytes ¶ added in v0.1.11
HumanBigIBytes produces a human readable representation of an IEC size.
See also: ParseHumanBigBytes.
HumanBigIBytes(82854982) -> 79 MiB
func HumanBigKbps ¶ added in v0.1.11
HumanBigKbps 1 Kbps = 1000 bit, 传输速率(bit per second, 位每秒) e.g. HumanBigKbps(82854982) -> 83 Mbps
func HumanBytes ¶ added in v0.1.3
HumanBytes 1 KB = 1000 B e.g. HumanBytes(82854982) -> 83 MB
func HumanIBytes ¶ added in v0.1.3
HumanIBytes 1 KiB = 1024 B e.g. HumanIBytes(82854982) -> 79 MiB
func HumanIntIBytes ¶ added in v0.1.4
HumanIntIBytes 1 KiB = 1024 B
func HumanKbps ¶ added in v0.1.11
HumanKbps 1 Kbps = 1000 bit, 传输速率(bit per second, 位每秒) e.g. HumanKbps(82854982) -> 83 Mbps
func IPv4String2Long ¶ added in v0.1.5
IPv4String2Long IPv4 字符串转数值
func InIPNetString ¶ added in v0.1.14
InIPNetString 是否包含在指定 IPNet 列表中
func IsInternalIPv4 ¶ added in v0.1.5
IsInternalIPv4 是否为内网 IPv4, 包含 NAT 专用网段 RFC6598, 比如华为云 ELB 的 100.125.0.0/16
func IsInternalIPv4String ¶ added in v0.1.5
IsInternalIPv4String 是否为内网 IPv4
func IsNil ¶ added in v0.1.8
func IsNil(i interface{}) bool
IsNil 判断对象(pointer, channel, func, interface, map, slice)是否为 nil nil 是一个 Type 类型的变量, Type 类型是基于 int 的类型 var 若变量本身是指针, 占用 8 字节, 指向类型内部结构体并置 0, 仅定义了变量本身, 此时为 nil
指针是非复合类型, 赋值 nil 时, 将 8 字节置 0, 即没有指向任何值的指针 0x0 map, channel: var 时仅定义了指针, 需要 make 初始化内部结构后才能使用, make 后非 nil
var 若变量非指针, 如 struct, int, 非 nil slice:
type slice struct, 占用 24 字节, 1 指针(array unsafe.Pointer) 2 个整型字段(len, cap int) var 定义后即可使用, 置 0 并分配, 此时 array 指针为 0 即没有实际数据时为 nil
interface:
type iface struct(interface 类型), type eface struct(空接口), 占用 16 字节 判断 data 指针为 0 即为 nil, 初始化后即非 0
func IsPrivateIP ¶ added in v0.2.1
IsPrivateIP reports whether ip is a private address, according to RFC 1918 (IPv4 addresses) and RFC 4193 (IPv6 addresses). Ref: go1.17+ func (ip IP) IsPrivate() bool
func IsPrivateIPString ¶ added in v0.2.1
IsPrivateIPString 是否为私有 IP
func LeftPadBytes ¶ added in v0.3.15
LeftPadBytes 从左填充到指定长度
func Long2IPv4String ¶ added in v0.1.5
Long2IPv4String 数值转 IPv4 字符串
func MD5BytesHex ¶ added in v0.4.3
func MustJSONIndent ¶ added in v0.1.7
func MustJSONIndent(v interface{}) []byte
MustJSONIndent 转 json 返回 []byte
func MustJSONIndentString ¶ added in v0.1.7
func MustJSONIndentString(v interface{}) string
MustJSONIndentString 转 json Indent 返回 string
func MustMD5Sum ¶ added in v0.4.4
func MustParseHumanBigBytes ¶ added in v0.3.13
MustParseHumanBigBytes 解析数字的数量级表示 e.g. MustParseHumanBigBytes("42 MB") -> 42000000 e.g. MustParseHumanBigBytes("-42 mib", 123) -> 123
func MustParseHumanBytes ¶ added in v0.3.13
MustParseHumanBytes 解析数字的数量级表示 e.g. MustParseHumanBytes("42 MB") -> 42000000 e.g. MustParseHumanBytes("-42 mib", 123) -> 123
func ParseHumanBigBytes ¶ added in v0.1.11
ParseHumanBigBytes parses a string representation of bytes into the number of bytes it represents.
See also: HumanBigBytes, HumanBigIBytes.
ParseHumanBigBytes("42 MB") -> 42000000, nil ParseHumanBigBytes("42 mib") -> 44040192, nil
func ParseHumanBytes ¶ added in v0.1.3
ParseHumanBytes 解析数字的数量级表示 e.g. ParseHumanBytes("42 MB") -> 42000000, nil e.g. ParseHumanBytes("42 mib") -> 44040192, nil
func RandHex ¶ added in v0.0.3
RandHex a random string containing only the following characters: 0123456789abcdef
func RandString ¶
RandString a random string, which may contain uppercase letters, lowercase letters and numbers. Ref: stackoverflow.icza
func RandUint32 ¶ added in v0.3.3
RandUint32 (>=)min - (<)max
func RemoveString ¶ added in v0.3.0
RemoveString 删除字符串元素
func ReplaceHost ¶ added in v0.3.2
ReplaceHost 返回 b 的主机名 + a 的端口 e.g. ReplaceHost("a.cn:77", "b.cn:88") == "b.cn:77"
func RightPadBytes ¶ added in v0.3.15
RightPadBytes 从右填充到指定长度
func Round ¶
Round 四舍五入, ROUND_HALF_UP 模式实现 返回将 val 根据指定精度 precision (十进制小数点后数字的数目) 进行四舍五入的结果 precision 也可以是负数或零 Ref: thinkeridea/go-extend
func SplitHostPort ¶ added in v0.3.2
SplitHostPort separates host and port. If the port is not valid, it returns the entire input as host, and it doesn't check the validity of the host. Unlike net.SplitHostPort, but per RFC 3986, it requires ports to be numeric.
func StrToBytes ¶ added in v0.1.3
StrToBytes Ref: Allenxuxu / toolkit
func String2Bytes ¶ added in v0.0.3
func StringToBytes ¶ added in v0.0.3
StringToBytes Ref: csdn.u010853261
func ToLowerBytes ¶ added in v0.3.2
ToLowerBytes converts ascii slice to lower-case Ref: fiber
func ToUpperBytes ¶ added in v0.3.2
ToUpperBytes converts ascii slice to upper-case Ref: fiber
func TrimLeftBytes ¶ added in v0.3.2
TrimLeftBytes is the equivalent of bytes.TrimLeft Ref: fiber
func TrimRightBytes ¶ added in v0.3.2
TrimRightBytes is the equivalent of bytes.TrimRight Ref: fiber
func ValidOptionalPort ¶ added in v0.3.2
ValidOptionalPort reports whether port is either an empty string or matches /^:\d*$/
Types ¶
type Bool ¶ added in v0.5.1
type Bool struct {
// contains filtered or unexported fields
}
A Bool is an atomic boolean value. The zero value is false.
func (*Bool) CompareAndSwap ¶ added in v0.5.2
CompareAndSwap executes the compare-and-swap operation for the boolean value x.
func (*Bool) MarshalJSON ¶ added in v0.5.1
func (*Bool) StoreFalse ¶ added in v0.5.1
func (x *Bool) StoreFalse()
func (*Bool) Swap ¶ added in v0.5.1
Swap atomically stores new into x and returns the previous value.
func (*Bool) Toggle ¶ added in v0.5.1
Toggle atomically negates the Boolean and returns the previous value
func (*Bool) UnmarshalJSON ¶ added in v0.5.1
type NoCmp ¶ added in v0.5.2
type NoCmp [0]func()
NoCmp is an uncomparable struct. Embed this inside another struct to make it uncomparable.
type Foo struct { NoCmp // ... }
This DOES NOT:
- Disallow shallow copies of structs
- Disallow comparison of pointers to uncomparable structs
type NoCopy ¶ added in v0.5.2
type NoCopy struct{} //nolint:unused
NoCopy may be added to structs which must not be copied after the first use.
See https://github.com/golang/go/issues/8005#issuecomment-190753527 for details. and also: https://stackoverflow.com/questions/52494458/nocopy-minimal-example
Note that it must not be embedded, due to the Lock and Unlock methods.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package base58 provides an API for working with modified base58 and Base58Check encodings.
|
Package base58 provides an API for working with modified base58 and Base58Check encodings. |
环境变量加密工具 go run main.go -d=Fufu go run main.go -d="Fufu 777" go run main.go -d=Fufu -k=TestEnv go run main.go -k=TestEnv go run main.go -u=db_user -p='abc!@#$%^&*()_+ ?><'
|
环境变量加密工具 go run main.go -d=Fufu go run main.go -d="Fufu 777" go run main.go -d=Fufu -k=TestEnv go run main.go -k=TestEnv go run main.go -u=db_user -p='abc!@#$%^&*()_+ ?><' |
avl
Package avl provides an implementation of an AVL tree.
|
Package avl provides an implementation of an AVL tree. |
btree
Package btree provides an implementation of a B-tree.
|
Package btree provides an implementation of a B-tree. |
cache
Package cache provides an implementation of a key-value store with a maximum size.
|
Package cache provides an implementation of a key-value store with a maximum size. |
constraints
Package constraints defines a set of useful constraints to be used with type parameters.
|
Package constraints defines a set of useful constraints to be used with type parameters. |
deepcopy
Package deepcopy implements the proposal https://go.dev/issue/51520.
|
Package deepcopy implements the proposal https://go.dev/issue/51520. |
hashmap
Package hashmap provides an implementation of a hashmap.
|
Package hashmap provides an implementation of a hashmap. |
hashset
Package hashset provides an implementation of a hashset.
|
Package hashset provides an implementation of a hashset. |
heap
Package heap provides an implementation of a binary heap.
|
Package heap provides an implementation of a binary heap. |
interval
Package interval provides an implementation of an interval tree built using an augmented AVL tree.
|
Package interval provides an implementation of an interval tree built using an augmented AVL tree. |
list
Package list provides an implementation of a doubly-linked list with a front and back.
|
Package list provides an implementation of a doubly-linked list with a front and back. |
maps
Package maps defines various functions useful with maps of any type.
|
Package maps defines various functions useful with maps of any type. |
mapset
Package mapset provides an implementation of a set using the built-in map.
|
Package mapset provides an implementation of a set using the built-in map. |
multimap
Package multimap provides an associative container that permits multiple entries with the same key.
|
Package multimap provides an associative container that permits multiple entries with the same key. |
queue
Package queue provides an implementation of a First In First Out (FIFO) queue.
|
Package queue provides an implementation of a First In First Out (FIFO) queue. |
rope
Package rope provides an implementation of a rope data structure.
|
Package rope provides an implementation of a rope data structure. |
slices
Package slices defines various functions useful with slices of any type.
|
Package slices defines various functions useful with slices of any type. |
stack
Package stack provides an implementation of a LIFO stack built using a resizing array.
|
Package stack provides an implementation of a LIFO stack built using a resizing array. |
trie
Package trie provides an implementation of a ternary search trie.
|
Package trie provides an implementation of a ternary search trie. |
Package ntp provides an implementation of a Simple NTP (SNTP) client capable of querying the current time from a remote NTP server.
|
Package ntp provides an implementation of a Simple NTP (SNTP) client capable of querying the current time from a remote NTP server. |
pools
|
|
sync
|
|
errgroup
Package errgroup provides synchronization, error propagation, and Context cancelation for groups of goroutines working on subtasks of a common task.
|
Package errgroup provides synchronization, error propagation, and Context cancelation for groups of goroutines working on subtasks of a common task. |
semaphore
Package semaphore provides a weighted semaphore implementation.
|
Package semaphore provides a weighted semaphore implementation. |
singleflight
Package singleflight provides a duplicate function call suppression mechanism.
|
Package singleflight provides a duplicate function call suppression mechanism. |
examples/auto_restart
本示例, 将启动一个后台运行的守护进程.
|
本示例, 将启动一个后台运行的守护进程. |
examples/background
本示例, 将把进程转为后台运行, 并保留所有参数不变
|
本示例, 将把进程转为后台运行, 并保留所有参数不变 |
Package xid is a globally unique id generator suited for web scale
|
Package xid is a globally unique id generator suited for web scale |
gjson
Package gjson provides searching for json strings.
|
Package gjson provides searching for json strings. |
jsongen
Package jsongen forked from darjun/json-gen
|
Package jsongen forked from darjun/json-gen |
match
Package match provides a simple pattern matcher with unicode support.
|
Package match provides a simple pattern matcher with unicode support. |
sjson
Package sjson provides setting json values.
|
Package sjson provides setting json values. |