utils

package module
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 44 Imported by: 26

README

Go-Utils

Go 常用的助手函数, 性能至上.

若有直接引用的, 会在函数定义或目录 README 中注明来源, 并保留 LICENSE, 感谢之!

安装

go get github.com/fufuok/utils

目录

package utils // import "github.com/fufuok/utils"

const Byte = 1 << (iota * 10) ...
const IByte = 1 ...
var BigByte ...
var BigSIByte ...
var Rand = NewRand()
var Seed = FastRand()
func AddString(s ...string) string
func AddStringBytes(s ...string) []byte
func AesCBCDeB58(s string, key []byte) []byte
func AesCBCDeB64(s string, key []byte) []byte
func AesCBCDeHex(s string, key []byte) []byte
func AesCBCDePKCS7B58(s string, key []byte) []byte
func AesCBCDePKCS7B64(s string, key []byte) []byte
func AesCBCDePKCS7Hex(s string, key []byte) []byte
func AesCBCDePKCS7StringB58(s string, key []byte) string
func AesCBCDePKCS7StringB64(s string, key []byte) string
func AesCBCDePKCS7StringHex(s string, key []byte) string
func AesCBCDeStringB58(s string, key []byte) string
func AesCBCDeStringB64(s string, key []byte) string
func AesCBCDeStringHex(s string, key []byte) string
func AesCBCDecrypt(asPKCS7 bool, ciphertext, key []byte, ivs ...[]byte) (plaintext []byte)
func AesCBCDecryptE(asPKCS7 bool, ciphertext, key []byte, ivs ...[]byte) ([]byte, error)
func AesCBCEnB58(b, key []byte) string
func AesCBCEnB64(b, key []byte) string
func AesCBCEnHex(b, key []byte) string
func AesCBCEnPKCS7B58(b, key []byte) string
func AesCBCEnPKCS7B64(b, key []byte) string
func AesCBCEnPKCS7Hex(b, key []byte) string
func AesCBCEnPKCS7StringB58(s string, key []byte) string
func AesCBCEnPKCS7StringB64(s string, key []byte) string
func AesCBCEnPKCS7StringHex(s string, key []byte) string
func AesCBCEnStringB58(s string, key []byte) string
func AesCBCEnStringB64(s string, key []byte) string
func AesCBCEnStringHex(s string, key []byte) string
func AesCBCEncrypt(asPKCS7 bool, plaintext, key []byte, ivs ...[]byte) (ciphertext []byte)
func AesCBCEncryptE(asPKCS7 bool, plaintext, key []byte, ivs ...[]byte) ([]byte, error)
func AesGCMDeB58(s string, key, nonce []byte) []byte
func AesGCMDeB64(s string, key, nonce []byte) []byte
func AesGCMDeHex(s string, key, nonce []byte) []byte
func AesGCMDeStringB58(s string, key, nonce []byte) string
func AesGCMDeStringB64(s string, key, nonce []byte) string
func AesGCMDeStringHex(s string, key, nonce []byte) string
func AesGCMDecrypt(ciphertext, key, nonce []byte) (plaintext []byte)
func AesGCMDecryptWithNonce(ciphertext, key, nonce, additionalData []byte) ([]byte, error)
func AesGCMEnB58(b, key []byte) (string, []byte)
func AesGCMEnB64(b, key []byte) (string, []byte)
func AesGCMEnHex(b, key []byte) (string, []byte)
func AesGCMEnStringB58(s string, key []byte) (string, []byte)
func AesGCMEnStringB64(s string, key []byte) (string, []byte)
func AesGCMEnStringHex(s string, key []byte) (string, []byte)
func AesGCMEncrypt(plaintext, key []byte) (ciphertext []byte, nonce []byte)
func AesGCMEncryptWithNonce(plaintext, key, nonce, additionalData []byte) ([]byte, []byte, error)
func AssertEqual(t 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 Decrypt(value, secret string) string
func DesCBCDeB58(s string, key []byte) []byte
func DesCBCDeB64(s string, key []byte) []byte
func DesCBCDeHex(s string, key []byte) []byte
func DesCBCDePKCS7B58(s string, key []byte) []byte
func DesCBCDePKCS7B64(s string, key []byte) []byte
func DesCBCDePKCS7Hex(s string, key []byte) []byte
func DesCBCDePKCS7StringB58(s string, key []byte) string
func DesCBCDePKCS7StringB64(s string, key []byte) string
func DesCBCDePKCS7StringHex(s string, key []byte) string
func DesCBCDeStringB58(s string, key []byte) string
func DesCBCDeStringB64(s string, key []byte) string
func DesCBCDeStringHex(s string, key []byte) string
func DesCBCDecrypt(asPKCS7 bool, ciphertext, key []byte, ivs ...[]byte) (plaintext []byte)
func DesCBCDecryptE(asPKCS7 bool, ciphertext, key []byte, ivs ...[]byte) ([]byte, error)
func DesCBCEnB58(b, key []byte) string
func DesCBCEnB64(b, key []byte) string
func DesCBCEnHex(b, key []byte) string
func DesCBCEnPKCS7B58(b, key []byte) string
func DesCBCEnPKCS7B64(b, key []byte) string
func DesCBCEnPKCS7Hex(b, key []byte) string
func DesCBCEnPKCS7StringB58(s string, key []byte) string
func DesCBCEnPKCS7StringB64(s string, key []byte) string
func DesCBCEnPKCS7StringHex(s string, key []byte) string
func DesCBCEnStringB58(s string, key []byte) string
func DesCBCEnStringB64(s string, key []byte) string
func DesCBCEnStringHex(s string, key []byte) string
func DesCBCEncrypt(asPKCS7 bool, plaintext, key []byte, ivs ...[]byte) (ciphertext []byte)
func DesCBCEncryptE(asPKCS7 bool, plaintext, key []byte, ivs ...[]byte) ([]byte, error)
func Djb33(s string) uint32
func EncodeUUID(id []byte) []byte
func Encrypt(value, secret string) string
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) (equals bool)
func EqualFoldBytes(b, s []byte) (equals 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 GCMDeB58(s string, key []byte) []byte
func GCMDeB64(s string, key []byte) []byte
func GCMDeHex(s string, key []byte) []byte
func GCMDeStringB58(s string, key []byte) string
func GCMDeStringB64(s string, key []byte) string
func GCMDeStringHex(s string, key []byte) string
func GCMDecrypt(encrypted, key []byte) ([]byte, error)
func GCMEnB58(b, key []byte) string
func GCMEnB64(b, key []byte) string
func GCMEnHex(b, key []byte) string
func GCMEnStringB58(s string, key []byte) string
func GCMEnStringB64(s string, key []byte) string
func GCMEnStringHex(s string, key []byte) string
func GCMEncrypt(plaintext, key []byte) ([]byte, error)
func GenRSAKey(bits int) (publicKey, privateKey []byte)
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 GetenvDecrypt(key string, secret string) string
func Hash(b []byte, h hash.Hash) []byte
func HashBytes(b ...[]byte) string
func HashBytesUint64(b ...[]byte) uint64
func HashString(s ...string) string
func HashStringUint64(s ...string) 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 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 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{}) 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 Padding(b []byte, bSize int, pkcs7 bool) []byte
func ParseHumanBigBytes(s string) (*big.Int, error)
func ParseHumanBytes(s string) (uint64, error)
func ParsePrivateKey(privateKey []byte) (priv *rsa.PrivateKey, err error)
func ParsePublicKey(publicKey []byte) (pub *rsa.PublicKey, err error)
func RSADecrypt(ciphertext, privateKey []byte) ([]byte, error)
func RSAEncrypt(plaintext, publicKey []byte) ([]byte, error)
func RSASign(data, privateKey []byte) ([]byte, error)
func RSASignVerify(data, publicKey, sig []byte) error
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 SetenvEncrypt(key, value, secret string) (string, error)
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) (b []byte)
func StringToBytes(s string) (b []byte)
func Sum32(s string) uint32
func Sum64(s string) 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 UnPadding(b []byte, pkcs7 bool) []byte
func Unzip(data []byte) (src []byte, err error)
func ValidOptionalPort(port string) bool
func WaitNextMinute()
func XOR(src, key []byte) []byte
func XORDeB58(s string, key []byte) []byte
func XORDeB64(s string, key []byte) []byte
func XORDeHex(s string, key []byte) []byte
func XORDeStringB58(s string, key []byte) string
func XORDeStringB64(s string, key []byte) string
func XORDeStringHex(s string, key []byte) string
func XORE(src, key []byte) ([]byte, error)
func XOREnB58(b, key []byte) string
func XOREnB64(b, key []byte) string
func XOREnHex(b, key []byte) string
func XOREnStringB58(s string, key []byte) string
func XOREnStringB64(s string, key []byte) string
func XOREnStringHex(s string, key []byte) string
func Zip(data []byte) ([]byte, error)
func ZipLevel(data []byte, level int) (dst []byte, err error)
加解密小工具

见: envtools

获取内外网 IP 小工具

见: myip

或: https://github.com/fufuok/myip

package myip // import "github.com/fufuok/utils/myip"

func ExternalIP(v ...string) string
func ExternalIPAny(retries ...int) string
func ExternalIPv4() string
func ExternalIPv6() string
func InternalIP(dstAddr, network string) string
func InternalIPv4() string
func InternalIPv6() string
func LocalIP() string
func LocalIPv4s() (ips []string)
编码解码 base58

见: base58

或: https://github.com/fufuok/basex

package base58 // import "github.com/fufuok/utils/base58"

func CheckDecode(input string) (result []byte, version byte, err error)
func CheckEncode(input []byte, version byte) string
func Decode(b string) []byte
func Encode(b []byte) string
可排序全局唯一 ID 生成器

比 UUID 更快, 更短

见: xid

或: http://github.com/fufuok/xid

package xid // import "github.com/fufuok/utils/xid"

func NewBytes() []byte
func NewString() string
func Sort(ids []ID)
type ID [rawLen]byte
    func FromBytes(b []byte) (ID, error)
    func FromString(id string) (ID, error)
    func New() ID
    func NewWithTime(t time.Time) ID
    func NilID() ID
自守护进程和后台运行

见: xdaemon

或: https://github.com/fufuok/xdaemon

package xdaemon // import "github.com/fufuok/utils/xdaemon"

const EnvName = "XW_DAEMON_IDX"
func Background(logFile string, isExit bool) (*exec.Cmd, error)
func NewSysProcAttr() *syscall.SysProcAttr
type Daemon struct{ ... }
    func NewDaemon(logFile string) *Daemon
高性能并发安全同步扩展库

见: xsync

或: https://github.com/fufuok/xsync

package xsync // import "github.com/fufuok/utils/xsync"

type Counter struct{ ... }
    func (c *Counter) Add(delta int64)
    func (c *Counter) Dec()
    func (c *Counter) Inc()
    func (c *Counter) Reset()
    func (c *Counter) Value() int64
type MPMCQueue struct{ ... }
    func NewMPMCQueue(capacity int) *MPMCQueue
    func (q *MPMCQueue) Dequeue() interface{}
    func (q *MPMCQueue) Enqueue(item interface{})
    func (q *MPMCQueue) TryDequeue() (item interface{}, ok bool)
    func (q *MPMCQueue) TryEnqueue(item interface{}) bool
type Map struct{ ... }
    func NewMap() *Map
    func (m *Map) Delete(key string)
    func (m *Map) Load(key string) (value interface{}, ok bool)
    func (m *Map) LoadAndDelete(key string) (value interface{}, loaded bool)
    func (m *Map) LoadOrStore(key string, value interface{}) (actual interface{}, loaded bool)
    func (m *Map) Range(f func(key string, value interface{}) bool)
    func (m *Map) Store(key string, value interface{})
type RBMutex struct{ ... }
    func (m *RBMutex) Lock()
    func (m *RBMutex) RLock() *RToken
    func (m *RBMutex) RUnlock(t *RToken)
    func (m *RBMutex) Unlock()
type RToken struct{ ... }
高效的 JSON 字符串生成器

见: jsongen

或: https://github.com/fufuok/jsongen

package jsongen // import "github.com/fufuok/utils/jsongen"

type Array []Value
    func NewArray() *Array
type Map struct{ ... }
    func NewMap() *Map
type QuotedValue string
type UnquotedValue string
type Value interface{ ... }
常用的池

[]byte 字节切片池化见: github.com/fufuok/bytespool

见: pools

package bufferpool // import "github.com/fufuok/utils/pools/bufferpool"

func Get() *bytes.Buffer
func New(bs []byte) *bytes.Buffer
func NewByte(c byte) *bytes.Buffer
func NewRune(r rune) *bytes.Buffer
func NewString(s string) *bytes.Buffer
func Put(buf *bytes.Buffer)
func Release(buf *bytes.Buffer) bool
func SetMaxSize(size int) bool

package readerpool // import "github.com/fufuok/utils/pools/readerpool"

func New(b []byte) *bytes.Reader
func Release(r *bytes.Reader)

package timerpool // import "github.com/fufuok/utils/pools/timerpool"

func New(d time.Duration) *time.Timer
func Release(t *time.Timer)

package tickerpool // import "github.com/fufuok/utils/pools/tickerpool"

func New(d time.Duration) *time.Ticker
func Release(t *time.Ticker)

使用

var s string
s = utils.GetString(123.45)         // "123.45"
s = utils.GetString(nil)            // ""
s = utils.GetString(nil, "default") // "default"
s = utils.GetString([]byte("ff"))   // "ff"
s = utils.GetString(true)           // "true"

x := utils.AddString(s, "OK") // "trueOK"

b := []byte("trueOK")
s = utils.B2S(b[0:1])                                     // "t"
safeS1 := utils.B2S([]byte(s[0:1]))                       // 转换为不可变字符串, CopyString 的实现
safeS2 := utils.CopyString(s[0:1])                        // 不可变字符串, s 可以被 GC 回收
safeS3 := utils.GetSafeString(s[0:1], "optional default") // 不可变字符串
safeS4 := utils.GetSafeB2S(b[0:1], "optional default")    // 转换为不可变字符串
safeS5 := string(b[0:1])                                  // 标准转换
b[0] = 70                                                 // 注意: 底层数组变化会引起字符串 s 发生改变
fmt.Println(s, safeS1, safeS2, safeS3, safeS4, safeS5)    // F t t t t t

x = utils.Encrypt("myData", "myKey")
fmt.Println(x) // Csi64LeQLmVhuZTh1xkCKM
x = utils.Decrypt("Csi64LeQLmVhuZTh1xkCKM", "myKey")
fmt.Println(x) // myData

k := utils.RandBytes(16)
x = utils.AesCBCEnPKCS7StringHex("myData", k)
fmt.Println(x) // 9dce01c049de7493ce2fae6a2707fad1
x = utils.AesCBCEnStringB58("myData", k)
fmt.Println(x) // 6NHTJhaW5mfeUioFLrbpRX

k = []byte("1234567812345678")
x = utils.GCMEnStringHex("myData", k)
fmt.Println(x) // 6501bb4737c772b9a2956d87183d4793d44b0e3c233bf2c6435d70502913d5701a98
x = utils.GCMEnStringB58("myData", k)
fmt.Println(x) // 5H9ftJvyBesQS7yNGoW7sBCqpwedpEhkjB7k4Z8QBi8GYJo

x = utils.GCMEnStringB64("myData", k)
fmt.Println(utils.GCMDeStringB64(x, k)) // myData

x = utils.UUIDString()
fmt.Println(x) // 04a49f17-8c37-44f7-a9c5-ea291c3736d7
x = utils.UUIDSimple()
fmt.Println(x) // 16123e98b35a4cea8e9cc127f379ff52
x = utils.UUIDShort()
fmt.Println(x) // Mw4hP7t9bnMMczU2AvyorU
x = xid.NewString()
fmt.Println(x) // c294bsnn5ek0ub0200fg

x = base58.Encode([]byte("Test data"))
fmt.Println(x) // 25JnwSn7XKfNQ
x = utils.B2S(base58.Decode("25JnwSn7XKfNQ"))
fmt.Println(x) // Test data

whoami := utils.Executable(true)
pwd := utils.ExecutableDir(true)
fmt.Println(whoami, pwd)

fmt.Println(utils.HumanBytes(1234567890))  // 1.2 GB
fmt.Println(utils.HumanIBytes(1234567890)) // 1.1 GiB
fmt.Println(utils.HumanKbps(1234567890))   // 1.2 Gbps
fmt.Println(utils.Commaf(1234567890.123))  // 1,234,567,890.123

now := time.Date(2020, 2, 18, 12, 13, 14, 123456789, time.UTC)
fmt.Println(utils.Get0LastWeek(now).Format(time.RFC3339Nano)) // 2020-02-10T00:00:00Z

fmt.Println(utils.GetNotInternalIPv4String("100.125.1.1", "", true))  // 100.125.1.1
fmt.Println(utils.GetNotInternalIPv4String("100.125.1.1", "1.2.3.4")) // 1.2.3.4
fmt.Println(utils.GetNotInternalIPv4String("192.168.1.1", "1.2.3.4")) // 1.2.3.4
fmt.Println(utils.GetNotInternalIPv4String("119.118.7.6", "1.2.3.4")) // 119.118.7.6

var nilN struct{}
var nilY *struct{}
fmt.Println(utils.IsNil(nilN), utils.IsNil(nilY)) // false true

public, private := utils.GenRSAKey(1024)
fmt.Println(string(public))
fmt.Println(string(private))

fmt.Println(utils.IsPrivateIPString("FC00::"))         // true
fmt.Println(utils.IsPrivateIPString("172.17.0.0"))     // true
fmt.Println(utils.IsInternalIPv4String("100.125.1.1")) // true

fmt.Println(utils.ToLower("TesT"))                                             // test
fmt.Println(utils.EqualFold(utils.Trim("/TesT/", '/'), utils.ToUpper("Test"))) // true

host, port := utils.SplitHostPort("demo.com:77")
fmt.Println(host) // demo.com
fmt.Println(port) // 77

fmt.Println(utils.Rand.Intn(10), utils.FastIntn(10))

dec, _ := utils.Zip(utils.FastRandBytes(3000))
src, _ := utils.Unzip(dec)
fmt.Println(len(dec), len(src)) // 2288 3000

type T struct {
    Name string `json:"name"`
}
t1 := T{"ff"}
buf := bufferpool.Get()
_ = json.NewEncoder(buf).Encode(&t1)
fmt.Println("json:", buf.String()) // json: {"name":"ff"}
bufferpool.Put(buf)

var t2 T
buf = bufferpool.Get()
buf.WriteString(`{"name":"ff"}`)
_ = json.NewDecoder(buf).Decode(&t2)
fmt.Printf("struct: %+v\n", t2)      // struct: {Name:ff}
fmt.Println("empty:", buf.Len() == 0) // empty: true
bufferpool.Put(buf)

js := jsongen.NewMap()
js.PutString("s", `a"b"\c`)
js.PutFloat("f", 3.14)
js.PutBool("b", false)
jsArr := jsongen.NewArray()
jsArr.AppendInt(7)
jsArr.AppendStringArray([]string{"A", "B"})
js.PutArray("sub", jsArr)
fmt.Printf("%s\n", js.Serialize(nil)) // {"s":"a\"b\"\\c","f":3.14,"b":false,"sub":[7,["A","B"]]}

ff

Documentation

Index

Constants

View Source
const (
	Byte = 1 << (iota * 10)
	KiByte
	MiByte
	GiByte
	TiByte
	PiByte
	EiByte
)

Ref: dustin/go-humanize IEC Sizes. kibis of bits

View Source
const (
	IByte = 1
	KByte = IByte * 1000
	MByte = KByte * 1000
	GByte = MByte * 1000
	TByte = GByte * 1000
	PByte = TByte * 1000
	EByte = PByte * 1000
)

SI Sizes.

Variables

View Source
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

View Source
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)
)
View Source
var Rand = NewRand()

Rand goroutine-safe, use Rand.xxx instead of rand.xxx

View Source
var Seed = FastRand()

Functions

func AddString

func AddString(s ...string) string

AddString 拼接字符串

func AddStringBytes

func AddStringBytes(s ...string) []byte

AddStringBytes 拼接字符串, 返回 bytes from bytes.Join()

func AesCBCDeB58 added in v0.0.3

func AesCBCDeB58(s string, key []byte) []byte

AesCBCDeB58 解密, ZerosPadding

func AesCBCDeB64

func AesCBCDeB64(s string, key []byte) []byte

AesCBCDeB64 解密, ZerosPadding

func AesCBCDeHex

func AesCBCDeHex(s string, key []byte) []byte

AesCBCDeHex 解密, ZerosPadding

func AesCBCDePKCS7B58 added in v0.0.3

func AesCBCDePKCS7B58(s string, key []byte) []byte

AesCBCDePKCS7B58 解密, Pkcs7Padding

func AesCBCDePKCS7B64

func AesCBCDePKCS7B64(s string, key []byte) []byte

AesCBCDePKCS7B64 解密, Pkcs7Padding

func AesCBCDePKCS7Hex

func AesCBCDePKCS7Hex(s string, key []byte) []byte

AesCBCDePKCS7Hex 解密, Pkcs7Padding

func AesCBCDePKCS7StringB58 added in v0.0.3

func AesCBCDePKCS7StringB58(s string, key []byte) string

AesCBCDePKCS7StringB58 解密, Pkcs7Padding

func AesCBCDePKCS7StringB64

func AesCBCDePKCS7StringB64(s string, key []byte) string

AesCBCDePKCS7StringB64 解密, Pkcs7Padding

func AesCBCDePKCS7StringHex

func AesCBCDePKCS7StringHex(s string, key []byte) string

AesCBCDePKCS7StringHex 解密, Pkcs7Padding

func AesCBCDeStringB58 added in v0.0.3

func AesCBCDeStringB58(s string, key []byte) string

AesCBCDeStringB58 解密, ZerosPadding

func AesCBCDeStringB64

func AesCBCDeStringB64(s string, key []byte) string

AesCBCDeStringB64 解密, ZerosPadding

func AesCBCDeStringHex

func AesCBCDeStringHex(s string, key []byte) string

AesCBCDeStringHex 解密, ZerosPadding

func AesCBCDecrypt

func AesCBCDecrypt(asPKCS7 bool, ciphertext, key []byte, ivs ...[]byte) (plaintext []byte)

AesCBCDecrypt AES-CBC 解密

func AesCBCDecryptE added in v0.0.3

func AesCBCDecryptE(asPKCS7 bool, ciphertext, key []byte, ivs ...[]byte) ([]byte, error)

AesCBCDecryptE AES-CBC 解密, 密码分组链接模式 (Cipher Block Chaining (CBC))

func AesCBCEnB58 added in v0.0.3

func AesCBCEnB58(b, key []byte) string

AesCBCEnB58 加密, ZerosPadding

func AesCBCEnB64

func AesCBCEnB64(b, key []byte) string

AesCBCEnB64 加密, ZerosPadding

func AesCBCEnHex

func AesCBCEnHex(b, key []byte) string

AesCBCEnHex 加密, ZerosPadding

func AesCBCEnPKCS7B58 added in v0.0.3

func AesCBCEnPKCS7B58(b, key []byte) string

AesCBCEnPKCS7B58 加密, Pkcs7Padding

func AesCBCEnPKCS7B64

func AesCBCEnPKCS7B64(b, key []byte) string

AesCBCEnPKCS7B64 加密, Pkcs7Padding

func AesCBCEnPKCS7Hex

func AesCBCEnPKCS7Hex(b, key []byte) string

AesCBCEnPKCS7Hex 加密, Pkcs7Padding

func AesCBCEnPKCS7StringB58 added in v0.0.3

func AesCBCEnPKCS7StringB58(s string, key []byte) string

AesCBCEnPKCS7StringB58 加密, Pkcs7Padding

func AesCBCEnPKCS7StringB64

func AesCBCEnPKCS7StringB64(s string, key []byte) string

AesCBCEnPKCS7StringB64 加密, Pkcs7Padding

func AesCBCEnPKCS7StringHex

func AesCBCEnPKCS7StringHex(s string, key []byte) string

AesCBCEnPKCS7StringHex 加密, Pkcs7Padding

func AesCBCEnStringB58 added in v0.0.3

func AesCBCEnStringB58(s string, key []byte) string

AesCBCEnStringB58 加密, ZerosPadding

func AesCBCEnStringB64

func AesCBCEnStringB64(s string, key []byte) string

AesCBCEnStringB64 加密, ZerosPadding

func AesCBCEnStringHex

func AesCBCEnStringHex(s string, key []byte) string

AesCBCEnStringHex 加密, ZerosPadding

func AesCBCEncrypt

func AesCBCEncrypt(asPKCS7 bool, plaintext, key []byte, ivs ...[]byte) (ciphertext []byte)

AesCBCEncrypt AES-CBC 加密

func AesCBCEncryptE added in v0.0.3

func AesCBCEncryptE(asPKCS7 bool, plaintext, key []byte, ivs ...[]byte) ([]byte, error)

AesCBCEncryptE AES-CBC 加密, 密码分组链接模式 (Cipher Block Chaining (CBC)) key 长度分别是 16 (AES-128), 24 (AES-192?), 32 (AES-256?) asPKCS7: false (ZerosPadding), true (Pkcs7Padding)

func AesGCMDeB58 added in v0.0.3

func AesGCMDeB58(s string, key, nonce []byte) []byte

AesGCMDeB58 解密

func AesGCMDeB64 added in v0.0.3

func AesGCMDeB64(s string, key, nonce []byte) []byte

AesGCMDeB64 解密

func AesGCMDeHex added in v0.0.3

func AesGCMDeHex(s string, key, nonce []byte) []byte

AesGCMDeHex 解密

func AesGCMDeStringB58 added in v0.0.3

func AesGCMDeStringB58(s string, key, nonce []byte) string

AesGCMDeStringB58 解密

func AesGCMDeStringB64 added in v0.0.3

func AesGCMDeStringB64(s string, key, nonce []byte) string

AesGCMDeStringB64 解密

func AesGCMDeStringHex added in v0.0.3

func AesGCMDeStringHex(s string, key, nonce []byte) string

AesGCMDeStringHex 解密

func AesGCMDecrypt added in v0.0.3

func AesGCMDecrypt(ciphertext, key, nonce []byte) (plaintext []byte)

AesGCMDecrypt AES-GCM 解密

func AesGCMDecryptWithNonce added in v0.0.3

func AesGCMDecryptWithNonce(ciphertext, key, nonce, additionalData []byte) ([]byte, error)

AesGCMDecryptWithNonce AES-GCM 解密, (Galois/Counter Mode (GCM))

func AesGCMEnB58 added in v0.0.3

func AesGCMEnB58(b, key []byte) (string, []byte)

AesGCMEnB58 加密

func AesGCMEnB64 added in v0.0.3

func AesGCMEnB64(b, key []byte) (string, []byte)

AesGCMEnB64 加密

func AesGCMEnHex added in v0.0.3

func AesGCMEnHex(b, key []byte) (string, []byte)

AesGCMEnHex 加密

func AesGCMEnStringB58 added in v0.0.3

func AesGCMEnStringB58(s string, key []byte) (string, []byte)

AesGCMEnStringB58 加密

func AesGCMEnStringB64 added in v0.0.3

func AesGCMEnStringB64(s string, key []byte) (string, []byte)

AesGCMEnStringB64 加密

func AesGCMEnStringHex added in v0.0.3

func AesGCMEnStringHex(s string, key []byte) (string, []byte)

AesGCMEnStringHex 加密

func AesGCMEncrypt added in v0.0.3

func AesGCMEncrypt(plaintext, key []byte) (ciphertext []byte, nonce []byte)

AesGCMEncrypt AES-GCM 加密

func AesGCMEncryptWithNonce added in v0.0.3

func AesGCMEncryptWithNonce(plaintext, key, nonce, additionalData []byte) ([]byte, []byte, error)

AesGCMEncryptWithNonce AES-GCM 加密, (Galois/Counter Mode (GCM)) key 长度分别是 16 (AES-128), 32 (AES-256)

func AssertEqual

func AssertEqual(t testing.TB, expected, actual interface{}, description ...string)

AssertEqual checks if values are equal Ref: gofiber/utils

func AssertPanics

func AssertPanics(t *testing.T, title string, f func())

AssertPanics 断言 panic

func B2S

func B2S(b []byte) string

B2S BytesToString

func B64Decode

func B64Decode(s string) []byte

B64Decode Base64 解码

func B64Encode

func B64Encode(b []byte) string

B64Encode Base64 编码

func B64UrlDecode

func B64UrlDecode(s string) []byte

B64UrlDecode Base64 解码

func B64UrlEncode

func B64UrlEncode(b []byte) string

B64UrlEncode Base64 解码, 安全 URL, 替换: "+/" 为 "-_"

func BeginOfDay added in v0.4.0

func BeginOfDay(t time.Time) time.Time

BeginOfDay 当天 0 点

func BeginOfHour added in v0.4.0

func BeginOfHour(t time.Time) time.Time

BeginOfHour 0 分

func BeginOfLastMonth added in v0.4.0

func BeginOfLastMonth(t time.Time) time.Time

BeginOfLastMonth 上月第一天 0 点

func BeginOfLastWeek added in v0.4.0

func BeginOfLastWeek(t time.Time) time.Time

BeginOfLastWeek 上周一 0 点

func BeginOfMinute added in v0.4.0

func BeginOfMinute(t time.Time) time.Time

BeginOfMinute 0 秒

func BeginOfMonth added in v0.4.0

func BeginOfMonth(t time.Time) time.Time

BeginOfMonth 当月第一天 0 点

func BeginOfNextMonth added in v0.4.0

func BeginOfNextMonth(t time.Time) time.Time

BeginOfNextMonth 下月第一天 0 点

func BeginOfNextWeek added in v0.4.0

func BeginOfNextWeek(t time.Time) time.Time

BeginOfNextWeek 下周一 0 点

func BeginOfTomorrow added in v0.4.0

func BeginOfTomorrow(t time.Time) time.Time

BeginOfTomorrow 明天 0 点

func BeginOfWeek added in v0.4.0

func BeginOfWeek(t time.Time) time.Time

BeginOfWeek 本周一 0 点

func BeginOfYear added in v0.4.0

func BeginOfYear(t time.Time) time.Time

BeginOfYear 本年第一天 0 点

func BeginOfYesterday added in v0.4.0

func BeginOfYesterday(t time.Time) time.Time

BeginOfYesterday 昨天 0 点

func BigComma added in v0.1.3

func BigComma(b *big.Int) string

BigComma big.Int 千分位分隔字符串 Ref: dustin/go-humanize

func BigCommaf added in v0.1.3

func BigCommaf(v *big.Float) string

BigCommaf big.Float 千分位分隔字符串 Ref: dustin/go-humanize

func Bigoom added in v0.1.3

func Bigoom(n, b *big.Int) (float64, int)

Bigoom big.Int 总数量级 Ref: dustin/go-humanize

func CPUTicks added in v0.3.3

func CPUTicks() int64

CPUTicks CPU 时钟周期, 更高精度 (云服务器做伪随机数种子时慎用)

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

func Comma(v int64) string

Comma 整数转千分位分隔字符串 Ref: dustin/go-humanize e.g. Comma(834142) -> 834,142

func Commaf added in v0.1.3

func Commaf(v float64) string

Commaf 浮点数转千分位分隔字符串 Ref: dustin/go-humanize e.g. Commaf(834142.32) -> 834,142.32

func Commai added in v0.1.4

func Commai(v int) string

Commai 整数转千分位分隔字符串

func Commau added in v0.1.3

func Commau(v uint64) string

Commau 整数转千分位分隔字符串 Ref: dustin/go-humanize

func CopyB2S added in v0.1.2

func CopyB2S(b []byte) string

CopyB2S Immutable, []byte to string string(b)

func CopyBytes

func CopyBytes(b []byte) []byte

CopyBytes Immutable, []byte to []byte

func CopyS2B added in v0.1.2

func CopyS2B(s string) []byte

CopyS2B Immutable, string to []byte []byte(s)

func CopyString

func CopyString(s string) string

CopyString Immutable, string to string e.g. fiberParam := utils.CopyString(c.Params("test")) e.g. utils.CopyString(s[500:1000]) // 可以让 s 被 GC 回收

func Decrypt

func Decrypt(value, secret string) string

Decrypt 解密

func DesCBCDeB58 added in v0.0.3

func DesCBCDeB58(s string, key []byte) []byte

DesCBCDeB58 解密, ZerosPadding

func DesCBCDeB64

func DesCBCDeB64(s string, key []byte) []byte

DesCBCDeB64 解密, ZerosPadding

func DesCBCDeHex

func DesCBCDeHex(s string, key []byte) []byte

DesCBCDeHex 解密, ZerosPadding

func DesCBCDePKCS7B58 added in v0.0.3

func DesCBCDePKCS7B58(s string, key []byte) []byte

DesCBCDePKCS7B58 解密, Pkcs7Padding

func DesCBCDePKCS7B64

func DesCBCDePKCS7B64(s string, key []byte) []byte

DesCBCDePKCS7B64 解密, Pkcs7Padding

func DesCBCDePKCS7Hex

func DesCBCDePKCS7Hex(s string, key []byte) []byte

DesCBCDePKCS7Hex 解密, Pkcs7Padding

func DesCBCDePKCS7StringB58 added in v0.0.3

func DesCBCDePKCS7StringB58(s string, key []byte) string

DesCBCDePKCS7StringB58 解密, Pkcs7Padding

func DesCBCDePKCS7StringB64

func DesCBCDePKCS7StringB64(s string, key []byte) string

DesCBCDePKCS7StringB64 解密, Pkcs7Padding

func DesCBCDePKCS7StringHex

func DesCBCDePKCS7StringHex(s string, key []byte) string

DesCBCDePKCS7StringHex 解密, Pkcs7Padding

func DesCBCDeStringB58 added in v0.0.3

func DesCBCDeStringB58(s string, key []byte) string

DesCBCDeStringB58 解密, ZerosPadding

func DesCBCDeStringB64

func DesCBCDeStringB64(s string, key []byte) string

DesCBCDeStringB64 解密, ZerosPadding

func DesCBCDeStringHex

func DesCBCDeStringHex(s string, key []byte) string

DesCBCDeStringHex 解密, ZerosPadding

func DesCBCDecrypt

func DesCBCDecrypt(asPKCS7 bool, ciphertext, key []byte, ivs ...[]byte) (plaintext []byte)

DesCBCDecrypt AES-CBC 解密

func DesCBCDecryptE added in v0.0.3

func DesCBCDecryptE(asPKCS7 bool, ciphertext, key []byte, ivs ...[]byte) ([]byte, error)

DesCBCDecryptE DES-CBC 解密, 密码分组链接模式 (Cipher Block Chaining (CBC))

func DesCBCEnB58 added in v0.0.3

func DesCBCEnB58(b, key []byte) string

DesCBCEnB58 加密, ZerosPadding

func DesCBCEnB64

func DesCBCEnB64(b, key []byte) string

DesCBCEnB64 加密, ZerosPadding

func DesCBCEnHex

func DesCBCEnHex(b, key []byte) string

DesCBCEnHex 加密, ZerosPadding

func DesCBCEnPKCS7B58 added in v0.0.3

func DesCBCEnPKCS7B58(b, key []byte) string

DesCBCEnPKCS7B58 加密, Pkcs7Padding

func DesCBCEnPKCS7B64

func DesCBCEnPKCS7B64(b, key []byte) string

DesCBCEnPKCS7B64 加密, Pkcs7Padding

func DesCBCEnPKCS7Hex

func DesCBCEnPKCS7Hex(b, key []byte) string

DesCBCEnPKCS7Hex 加密, Pkcs7Padding

func DesCBCEnPKCS7StringB58 added in v0.0.3

func DesCBCEnPKCS7StringB58(s string, key []byte) string

DesCBCEnPKCS7StringB58 加密, Pkcs7Padding

func DesCBCEnPKCS7StringB64

func DesCBCEnPKCS7StringB64(s string, key []byte) string

DesCBCEnPKCS7StringB64 加密, Pkcs7Padding

func DesCBCEnPKCS7StringHex

func DesCBCEnPKCS7StringHex(s string, key []byte) string

DesCBCEnPKCS7StringHex 加密, Pkcs7Padding

func DesCBCEnStringB58 added in v0.0.3

func DesCBCEnStringB58(s string, key []byte) string

DesCBCEnStringB58 加密, ZerosPadding

func DesCBCEnStringB64

func DesCBCEnStringB64(s string, key []byte) string

DesCBCEnStringB64 加密, ZerosPadding

func DesCBCEnStringHex

func DesCBCEnStringHex(s string, key []byte) string

DesCBCEnStringHex 加密, ZerosPadding

func DesCBCEncrypt

func DesCBCEncrypt(asPKCS7 bool, plaintext, key []byte, ivs ...[]byte) (ciphertext []byte)

DesCBCEncrypt AES-CBC 加密

func DesCBCEncryptE added in v0.0.3

func DesCBCEncryptE(asPKCS7 bool, plaintext, key []byte, ivs ...[]byte) ([]byte, error)

DesCBCEncryptE DES-CBC 加密, 密码分组链接模式 (Cipher Block Chaining (CBC)) key 长度固定为 8 asPKCS7: false (ZerosPadding), true (Pkcs7Padding)

func Djb33 added in v0.3.3

func Djb33(s string) uint32

Djb33 比 FnvHash32 更快的获取字符串哈希值 djb2 with better shuffling. 5x faster than FNV with the hash.Hash overhead. Ref: patrickmn/go-cache

func EncodeUUID added in v0.0.3

func EncodeUUID(id []byte) []byte

EncodeUUID 编码 UUID

func Encrypt

func Encrypt(value, secret string) string

Encrypt 加密 (密钥取 32 位 MD5, AES-CBC, base58)

func EndOfDay added in v0.4.0

func EndOfDay(t time.Time) time.Time

EndOfDay 当天最后时刻

func EndOfHour added in v0.4.0

func EndOfHour(t time.Time) time.Time

EndOfHour 最后一分

func EndOfLastMonth added in v0.4.0

func EndOfLastMonth(t time.Time) time.Time

EndOfLastMonth 上月最后一刻

func EndOfLastWeek added in v0.4.0

func EndOfLastWeek(t time.Time) time.Time

EndOfLastWeek 上周一最后一刻

func EndOfMinute added in v0.4.0

func EndOfMinute(t time.Time) time.Time

EndOfMinute 最后一秒

func EndOfMonth added in v0.4.0

func EndOfMonth(t time.Time) time.Time

EndOfMonth 当月最后一刻

func EndOfNextMonth added in v0.4.0

func EndOfNextMonth(t time.Time) time.Time

EndOfNextMonth 下月最后一刻

func EndOfNextWeek added in v0.4.0

func EndOfNextWeek(t time.Time) time.Time

EndOfNextWeek 下周一最后一刻

func EndOfTomorrow added in v0.4.0

func EndOfTomorrow(t time.Time) time.Time

EndOfTomorrow 明天 0 点

func EndOfWeek added in v0.4.0

func EndOfWeek(t time.Time) time.Time

EndOfWeek 本周末最后一刻

func EndOfYear added in v0.4.0

func EndOfYear(t time.Time) time.Time

EndOfYear 本年最后一刻

func EndOfYesterday added in v0.4.0

func EndOfYesterday(t time.Time) time.Time

EndOfYesterday 昨天最后时刻

func EqualFold added in v0.3.2

func EqualFold(b, s string) (equals bool)

EqualFold the equivalent of strings.EqualFold Ref: fiber

func EqualFoldBytes added in v0.3.2

func EqualFoldBytes(b, s []byte) (equals bool)

EqualFoldBytes the equivalent of bytes.EqualFold Ref: fiber

func Executable added in v0.1.2

func Executable(evalSymlinks ...bool) string

Executable 当前执行程序绝对路径 true 时返回解析符号链接后的绝对路径 Excutable: E:\tmp\linkapp.exe Excutable(true): D:\Fufu\Test\abc\app.exe

func ExecutableDir added in v0.1.2

func ExecutableDir(evalSymlinks ...bool) string

ExecutableDir 当前执行程序所在目录 true 时返回解析符号链接后的目录 ExcutableDir: E:\tmp ExcutableDir(true): D:\Fufu\Test\abc

func FastIntn added in v0.3.3

func FastIntn(n int) int

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 FastRand added in v0.3.3

func FastRand() uint32

FastRand 随机数

func FastRandBytes added in v0.3.3

func FastRandBytes(n int) []byte

FastRandBytes random bytes, but faster.

func FastRandn added in v0.3.3

func FastRandn(n uint32) uint32

FastRandn 等同于 FastRand() % n, 但更快 See https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/

func FnvHash added in v0.3.3

func FnvHash(s string) uint64

FnvHash 获取字符串的哈希值

func FnvHash32 added in v0.3.3

func FnvHash32(s string) uint32

FnvHash32 获取字符串的哈希值

func GCMDeB58 added in v0.2.1

func GCMDeB58(s string, key []byte) []byte

GCMDeB58 解密

func GCMDeB64 added in v0.2.1

func GCMDeB64(s string, key []byte) []byte

GCMDeB64 解密

func GCMDeHex added in v0.2.1

func GCMDeHex(s string, key []byte) []byte

GCMDeHex 解密

func GCMDeStringB58 added in v0.2.1

func GCMDeStringB58(s string, key []byte) string

GCMDeStringB58 解密

func GCMDeStringB64 added in v0.2.1

func GCMDeStringB64(s string, key []byte) string

GCMDeStringB64 解密

func GCMDeStringHex added in v0.2.1

func GCMDeStringHex(s string, key []byte) string

GCMDeStringHex 解密

func GCMDecrypt added in v0.2.1

func GCMDecrypt(encrypted, key []byte) ([]byte, error)

GCMDecrypt AES-GCM 解密

func GCMEnB58 added in v0.2.1

func GCMEnB58(b, key []byte) string

GCMEnB58 加密

func GCMEnB64 added in v0.2.1

func GCMEnB64(b, key []byte) string

GCMEnB64 加密

func GCMEnHex added in v0.2.1

func GCMEnHex(b, key []byte) string

GCMEnHex 加密

func GCMEnStringB58 added in v0.2.1

func GCMEnStringB58(s string, key []byte) string

GCMEnStringB58 加密

func GCMEnStringB64 added in v0.2.1

func GCMEnStringB64(s string, key []byte) string

GCMEnStringB64 加密

func GCMEnStringHex added in v0.2.1

func GCMEnStringHex(s string, key []byte) string

GCMEnStringHex 加密

func GCMEncrypt added in v0.2.1

func GCMEncrypt(plaintext, key []byte) ([]byte, error)

GCMEncrypt AES-GCM 加密

func GenRSAKey added in v0.1.10

func GenRSAKey(bits int) (publicKey, privateKey []byte)

GenRSAKey 生成 RSA 密钥对 openssl genrsa -out rsa_private_key.pem 1024 openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem

func GetBytes

func GetBytes(v interface{}, defaultVal ...[]byte) []byte

GetBytes 先转为字符串再转为 []byte, 可选指定默认值

func GetIPPort added in v0.2.0

func GetIPPort(addr net.Addr) (ip net.IP, port int, err error)

GetIPPort 返回 IP 和 端口

func GetInt

func GetInt(v interface{}, defaultInt ...int) int

GetInt 获取 int 结果, 可选指定默认值(若给定了默认值,则返回正整数或 0)

func GetMonthDays added in v0.1.5

func GetMonthDays(t time.Time) int

GetMonthDays 当月天数

func GetNotInternalIPv4 added in v0.1.5

func GetNotInternalIPv4(ip, defaultIP net.IP, flag ...bool) net.IP

GetNotInternalIPv4 如果是内网 IPv4 则使用默认值, flag 为真是必定返回一个 IP

func GetNotInternalIPv4String added in v0.1.5

func GetNotInternalIPv4String(ip, defaultIP string, flag ...bool) string

GetNotInternalIPv4String 如果是内网 IPv4 则使用默认值

func GetSafeB2S added in v0.1.1

func GetSafeB2S(b []byte, defaultVal ...string) string

GetSafeB2S Immutable, 可选指定默认值

func GetSafeBytes added in v0.1.1

func GetSafeBytes(b []byte, defaultVal ...[]byte) []byte

GetSafeBytes Immutable, 可选指定默认值

func GetSafeS2B added in v0.1.1

func GetSafeS2B(s string, defaultVal ...[]byte) []byte

GetSafeS2B Immutable, 可选指定默认值

func GetSafeString added in v0.1.1

func GetSafeString(s string, defaultVal ...string) string

GetSafeString Immutable, 可选指定默认值

func GetString

func GetString(v interface{}, defaultVal ...string) string

GetString 获取字符串结果, 可选指定默认值

func GetenvDecrypt

func GetenvDecrypt(key string, secret string) string

GetenvDecrypt 解密环境变量参数(string)

func Hash

func Hash(b []byte, h hash.Hash) []byte

func HashBytes added in v0.3.11

func HashBytes(b ...[]byte) string

HashBytes 合并 Bytes, 得到字符串哈希

func HashBytesUint64 added in v0.3.11

func HashBytesUint64(b ...[]byte) uint64

func HashString added in v0.3.11

func HashString(s ...string) string

HashString 合并一串文本, 得到字符串哈希

func HashStringUint64 added in v0.3.11

func HashStringUint64(s ...string) uint64

func Hmac

func Hmac(b []byte, key []byte, h func() hash.Hash) []byte

func HmacSHA1

func HmacSHA1(b, key []byte) []byte

func HmacSHA1Hex

func HmacSHA1Hex(s, key string) string

func HmacSHA256

func HmacSHA256(b, key []byte) []byte

func HmacSHA256Hex

func HmacSHA256Hex(s, key string) string

func HmacSHA512

func HmacSHA512(b, key []byte) []byte

func HmacSHA512Hex

func HmacSHA512Hex(s, key string) string

func HumanBaseBytes added in v0.1.3

func HumanBaseBytes(v uint64, base float64, sizes []string) string

HumanBaseBytes 数字的数量级表示

func HumanBigBytes added in v0.1.11

func HumanBigBytes(s *big.Int) string

HumanBigBytes produces a human readable representation of an SI size.

See also: ParseHumanBigBytes.

HumanBigBytes(82854982) -> 83 MB

func HumanBigIBytes added in v0.1.11

func HumanBigIBytes(s *big.Int) string

HumanBigIBytes produces a human readable representation of an IEC size.

See also: ParseHumanBigBytes.

HumanBigIBytes(82854982) -> 79 MiB

func HumanBigKbps added in v0.1.11

func HumanBigKbps(s *big.Int) string

HumanBigKbps 1 Kbps = 1000 bit, 传输速率(bit per second, 位每秒) e.g. HumanBigKbps(82854982) -> 83 Mbps

func HumanBytes added in v0.1.3

func HumanBytes(v uint64) string

HumanBytes 1 KB = 1000 B e.g. HumanBytes(82854982) -> 83 MB

func HumanGBMB added in v0.4.2

func HumanGBMB(v uint64) string

HumanGBMB 转为 ** GB ** MB 1 GB = 1024 MB

func HumanIBytes added in v0.1.3

func HumanIBytes(v uint64) string

HumanIBytes 1 KiB = 1024 B e.g. HumanIBytes(82854982) -> 79 MiB

func HumanIntBytes added in v0.1.4

func HumanIntBytes(v int) string

HumanIntBytes 1 KB = 1000 B

func HumanIntIBytes added in v0.1.4

func HumanIntIBytes(v int) string

HumanIntIBytes 1 KiB = 1024 B

func HumanIntKbps added in v0.1.11

func HumanIntKbps(v int) string

HumanIntKbps 1 Kbps = 1000 bit

func HumanKbps added in v0.1.11

func HumanKbps(v uint64) string

HumanKbps 1 Kbps = 1000 bit, 传输速率(bit per second, 位每秒) e.g. HumanKbps(82854982) -> 83 Mbps

func IPv42Long added in v0.1.5

func IPv42Long(ip net.IP) int

IPv42Long IPv4 转数值

func IPv4String2Long added in v0.1.5

func IPv4String2Long(ip string) int

IPv4String2Long IPv4 字符串转数值

func InIPNet added in v0.1.14

func InIPNet(ip net.IP, ipNets map[*net.IPNet]struct{}) bool

InIPNet 是否包含在指定 IPNet 列表中

func InIPNetString added in v0.1.14

func InIPNetString(ip string, ipNets map[*net.IPNet]struct{}) bool

InIPNetString 是否包含在指定 IPNet 列表中

func InInts

func InInts(slice []int, n int) bool

InInts 检查整数是否存在于 slice

func InStrings

func InStrings(ss []string, s string) bool

InStrings 检查字符串是否存在于 slice

func IsDir

func IsDir(s string) bool

IsDir 目录是否存在

func IsExist

func IsExist(s string) bool

IsExist 文件或目录是否存在

func IsFile

func IsFile(s string) bool

IsFile 文件是否存在

func IsInternalIPv4 added in v0.1.5

func IsInternalIPv4(ip net.IP) bool

IsInternalIPv4 是否为内网 IPv4, 包含 NAT 专用网段 RFC6598, 比如华为云 ELB 的 100.125.0.0/16

func IsInternalIPv4String added in v0.1.5

func IsInternalIPv4String(ip string) bool

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

func IsPrivateIP(ip net.IP) bool

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

func IsPrivateIPString(ip string) bool

IsPrivateIPString 是否为私有 IP

func JoinBytes

func JoinBytes(b ...[]byte) []byte

JoinBytes 拼接 []byte

func LeftPad added in v0.3.15

func LeftPad(s, pad string, n int) string

LeftPad 从左填充字符串到指定长度

func LeftPadBytes added in v0.3.15

func LeftPadBytes(b, pad []byte, n int) []byte

LeftPadBytes 从左填充到指定长度

func Logn added in v0.1.3

func Logn(n, b float64) float64

func Long2IPv4 added in v0.1.5

func Long2IPv4(n int) net.IP

Long2IPv4 数值转 IPv4

func Long2IPv4String added in v0.1.5

func Long2IPv4String(n int) string

Long2IPv4String 数值转 IPv4 字符串

func MD5

func MD5(b []byte) []byte

func MD5BytesHex added in v0.4.3

func MD5BytesHex(bs []byte) string

func MD5Hex

func MD5Hex(s string) string

MD5Hex 字符串 MD5

func MD5Reader

func MD5Reader(r io.Reader) (string, error)

MD5Reader 计算 MD5

func MD5Sum

func MD5Sum(filename string) (string, error)

MD5Sum 文件 MD5

func MaxInt

func MaxInt(a, b int) int

MaxInt 整数取大值

func MemHash added in v0.3.3

func MemHash(s string) uint64

MemHash 使用内置的 memhash 获取字符串哈希值

func MemHash32 added in v0.3.3

func MemHash32(s string) uint32

MemHash32 使用内置的 memhash 获取字符串哈希值

func MemHashb added in v0.3.3

func MemHashb(b []byte) uint64

MemHashb 使用内置的 memhash 获取哈希值

func MemHashb32 added in v0.3.3

func MemHashb32(b []byte) uint32

MemHashb32 使用内置的 memhash 获取哈希值

func MinInt

func MinInt(a, b int) int

MinInt 整数取小值

func MustBool

func MustBool(v interface{}) bool

MustBool 强制转为 bool

func MustInt

func MustInt(v interface{}) int

MustInt 强制转为整数 (int)

func MustJSON

func MustJSON(v interface{}) []byte

MustJSON 转 json 返回 []byte

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 MustJSONString

func MustJSONString(v interface{}) string

MustJSONString 转 json 返回 string

func MustMD5Sum added in v0.4.4

func MustMD5Sum(filename string) string

func MustParseHumanBigBytes added in v0.3.13

func MustParseHumanBigBytes(s string, defaultVal ...*big.Int) *big.Int

MustParseHumanBigBytes 解析数字的数量级表示 e.g. MustParseHumanBigBytes("42 MB") -> 42000000 e.g. MustParseHumanBigBytes("-42 mib", 123) -> 123

func MustParseHumanBytes added in v0.3.13

func MustParseHumanBytes(s string, defaultVal ...uint64) uint64

MustParseHumanBytes 解析数字的数量级表示 e.g. MustParseHumanBytes("42 MB") -> 42000000 e.g. MustParseHumanBytes("-42 mib", 123) -> 123

func MustString

func MustString(v interface{}) string

MustString 强制转为字符串

func NanoTime added in v0.3.3

func NanoTime() int64

NanoTime 返回当前时间 (以纳秒为单位)

func NewRand added in v0.3.3

func NewRand(seed ...int64) *rand.Rand

NewRand goroutine-safe rand.Rand, optional seed value

func Pad added in v0.3.15

func Pad(s, pad string, n int) string

Pad 填充字符串到指定长度, 同 Python3: 'str'.center()

func PadBytes added in v0.3.15

func PadBytes(s, pad []byte, n int) []byte

PadBytes 填充到指定长度

func Padding

func Padding(b []byte, bSize int, pkcs7 bool) []byte

Padding 填充

func ParseHumanBigBytes added in v0.1.11

func ParseHumanBigBytes(s string) (*big.Int, error)

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

func ParseHumanBytes(s string) (uint64, error)

ParseHumanBytes 解析数字的数量级表示 e.g. ParseHumanBytes("42 MB") -> 42000000, nil e.g. ParseHumanBytes("42 mib") -> 44040192, nil

func ParsePrivateKey added in v0.1.10

func ParsePrivateKey(privateKey []byte) (priv *rsa.PrivateKey, err error)

ParsePrivateKey parses an RSA private key in PKCS #1, ASN.1 DER form.

func ParsePublicKey added in v0.1.10

func ParsePublicKey(publicKey []byte) (pub *rsa.PublicKey, err error)

ParsePublicKey parses a public key in PKIX, ASN.1 DER form.

func RSADecrypt added in v0.1.10

func RSADecrypt(ciphertext, privateKey []byte) ([]byte, error)

RSADecrypt 私钥解密

func RSAEncrypt added in v0.1.10

func RSAEncrypt(plaintext, publicKey []byte) ([]byte, error)

RSAEncrypt 公钥加密

func RSASign added in v0.1.10

func RSASign(data, privateKey []byte) ([]byte, error)

RSASign 私钥签名

func RSASignVerify added in v0.1.10

func RSASignVerify(data, publicKey, sig []byte) error

RSASignVerify 公钥验证签名

func RandBytes added in v0.0.3

func RandBytes(n int) []byte

RandBytes random bytes

func RandHex added in v0.0.3

func RandHex(nHalf int) string

RandHex a random string containing only the following characters: 0123456789abcdef

func RandInt

func RandInt(min, max int) int

RandInt (>=)min - (<)max

func RandString

func RandString(n int) string

RandString a random string, which may contain uppercase letters, lowercase letters and numbers. Ref: stackoverflow.icza

func RandUint32 added in v0.3.3

func RandUint32(min, max uint32) uint32

RandUint32 (>=)min - (<)max

func RemoveString added in v0.3.0

func RemoveString(ss []string, s string) ([]string, bool)

RemoveString 删除字符串元素

func ReplaceHost added in v0.3.2

func ReplaceHost(a, b string) string

ReplaceHost 返回 b 的主机名 + a 的端口 e.g. ReplaceHost("a.cn:77", "b.cn:88") == "b.cn:77"

func RightPad added in v0.3.15

func RightPad(s, pad string, n int) string

RightPad 从右填充字符串到指定长度

func RightPadBytes added in v0.3.15

func RightPadBytes(b, pad []byte, n int) []byte

RightPadBytes 从右填充到指定长度

func Round

func Round(v float64, precision int) float64

Round 四舍五入, ROUND_HALF_UP 模式实现 返回将 val 根据指定精度 precision (十进制小数点后数字的数目) 进行四舍五入的结果 precision 也可以是负数或零 Ref: thinkeridea/go-extend

func RunPath

func RunPath() string

RunPath 实际程序所在目录 RunPath: E:\tmp

func S2B

func S2B(s string) []byte

S2B StringToBytes converts string to byte slice without a memory allocation. Ref: gin

func SearchInt

func SearchInt(slice []int, n int) int

SearchInt 搜索整数位置(左, 第一个)

func SearchString

func SearchString(ss []string, s string) int

SearchString 搜索字符串位置(左, 第一个)

func SetenvEncrypt

func SetenvEncrypt(key, value, secret string) (string, error)

SetenvEncrypt 加密并设置环境变量(string)

func Sha1

func Sha1(b []byte) []byte

func Sha1Hex

func Sha1Hex(s string) string

func Sha256

func Sha256(b []byte) []byte

func Sha256Hex

func Sha256Hex(s string) string

func Sha512

func Sha512(b []byte) []byte

func Sha512Hex

func Sha512Hex(s string) string

func SplitHostPort added in v0.3.2

func SplitHostPort(hostPort string) (host, port string)

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 Str2Bytes added in v0.0.3

func Str2Bytes(s string) (b []byte)

Str2Bytes Ref: csdn.weixin_43705457

func StrToBytes added in v0.1.3

func StrToBytes(s string) []byte

StrToBytes Ref: Allenxuxu / toolkit

func String2Bytes added in v0.0.3

func String2Bytes(s string) (b []byte)

String2Bytes Ref: fasthttp

func StringToBytes added in v0.0.3

func StringToBytes(s string) (b []byte)

StringToBytes Ref: csdn.u010853261

func Sum32 added in v0.3.3

func Sum32(s string) uint32

Sum32 获取字符串的哈希值

func Sum64 added in v0.3.3

func Sum64(s string) uint64

Sum64 获取字符串的哈希值

func SumInt added in v0.3.3

func SumInt(v ...int) int

SumInt 整数和

func ToLower added in v0.3.2

func ToLower(b string) string

ToLower is the equivalent of strings.ToLower Ref: fiber

func ToLowerBytes added in v0.3.2

func ToLowerBytes(b []byte) []byte

ToLowerBytes is the equivalent of bytes.ToLower Ref: fiber

func ToUpper added in v0.3.2

func ToUpper(b string) string

ToUpper is the equivalent of strings.ToUpper Ref: fiber

func ToUpperBytes added in v0.3.2

func ToUpperBytes(b []byte) []byte

ToUpperBytes is the equivalent of bytes.ToUpper Ref: fiber

func Trim added in v0.3.2

func Trim(s string, cutset byte) string

Trim is the equivalent of strings.Trim Ref: fiber

func TrimBytes added in v0.3.2

func TrimBytes(b []byte, cutset byte) []byte

TrimBytes is the equivalent of bytes.Trim Ref: fiber

func TrimLeft added in v0.3.2

func TrimLeft(s string, cutset byte) string

TrimLeft is the equivalent of strings.TrimLeft Ref: fiber

func TrimLeftBytes added in v0.3.2

func TrimLeftBytes(b []byte, cutset byte) []byte

TrimLeftBytes is the equivalent of bytes.TrimLeft Ref: fiber

func TrimRight added in v0.3.2

func TrimRight(s string, cutset byte) string

TrimRight is the equivalent of strings.TrimRight Ref: fiber

func TrimRightBytes added in v0.3.2

func TrimRightBytes(b []byte, cutset byte) []byte

TrimRightBytes is the equivalent of bytes.TrimRight Ref: fiber

func UUID added in v0.0.3

func UUID() []byte

UUID 随机 UUID, RFC4122, Version 4

func UUIDShort added in v0.0.3

func UUIDShort() string

UUIDShort 随机 UUID, 短版, base58

func UUIDSimple added in v0.0.3

func UUIDSimple() string

UUIDSimple 随机 UUID, 无短横线

func UUIDString added in v0.0.3

func UUIDString() string

UUIDString 随机 UUID

func UnPadding

func UnPadding(b []byte, pkcs7 bool) []byte

UnPadding 去除填充

func Unzip added in v0.3.4

func Unzip(data []byte) (src []byte, err error)

func ValidOptionalPort added in v0.3.2

func ValidOptionalPort(port string) bool

ValidOptionalPort reports whether port is either an empty string or matches /^:\d*$/

func WaitNextMinute

func WaitNextMinute()

WaitNextMinute 下一分钟, 对齐时间, 0 秒

func XOR added in v0.1.10

func XOR(src, key []byte) []byte

XOR 异或加解密

func XORDeB58 added in v0.1.10

func XORDeB58(s string, key []byte) []byte

XORDeB58 解密

func XORDeB64 added in v0.1.10

func XORDeB64(s string, key []byte) []byte

XORDeB64 解密

func XORDeHex added in v0.1.10

func XORDeHex(s string, key []byte) []byte

XORDeHex 解密

func XORDeStringB58 added in v0.1.10

func XORDeStringB58(s string, key []byte) string

XORDeStringB58 解密

func XORDeStringB64 added in v0.1.10

func XORDeStringB64(s string, key []byte) string

XORDeStringB64 解密

func XORDeStringHex added in v0.1.10

func XORDeStringHex(s string, key []byte) string

XORDeStringHex 解密

func XORE added in v0.1.10

func XORE(src, key []byte) ([]byte, error)

XORE RC4 加密算法(异或运算), 简单加解密, 不够安全 key 长度是 1-256

func XOREnB58 added in v0.1.10

func XOREnB58(b, key []byte) string

XOREnB58 加密

func XOREnB64 added in v0.1.10

func XOREnB64(b, key []byte) string

XOREnB64 加密

func XOREnHex added in v0.1.10

func XOREnHex(b, key []byte) string

XOREnHex 加密

func XOREnStringB58 added in v0.1.10

func XOREnStringB58(s string, key []byte) string

XOREnStringB58 加密

func XOREnStringB64 added in v0.1.10

func XOREnStringB64(s string, key []byte) string

XOREnStringB64 加密

func XOREnStringHex added in v0.1.10

func XOREnStringHex(s string, key []byte) string

XOREnStringHex 加密

func Zip added in v0.3.4

func Zip(data []byte) ([]byte, error)

func ZipLevel added in v0.3.7

func ZipLevel(data []byte, level int) (dst []byte, err error)

Types

This section is empty.

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 -d=Fufu go run main.go -d="Fufu 777" go run main.go -d=Fufu -k=TestEnv go run main.go -k=TestEnv
Package jsongen forked from darjun/json-gen
Package jsongen forked from darjun/json-gen
pools
examples/auto_restart
本示例, 将启动一个后台运行的守护进程.
本示例, 将启动一个后台运行的守护进程.
examples/background
本示例, 将把进程转为后台运行, 并保留所有参数不变
本示例, 将把进程转为后台运行, 并保留所有参数不变
Package xid is a globally unique id generator suited for web scale Xid is using Mongo Object ID algorithm to generate globally unique ids: https://docs.mongodb.org/manual/reference/object-id/ - 4-byte value representing the seconds since the Unix epoch, - 3-byte machine identifier, - 2-byte process id, and - 3-byte counter, starting with a random value.
Package xid is a globally unique id generator suited for web scale Xid is using Mongo Object ID algorithm to generate globally unique ids: https://docs.mongodb.org/manual/reference/object-id/ - 4-byte value representing the seconds since the Unix epoch, - 3-byte machine identifier, - 2-byte process id, and - 3-byte counter, starting with a random value.

Jump to

Keyboard shortcuts

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