utils

package
v0.0.0-...-43a62c1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2023 License: MIT Imports: 38 Imported by: 0

README

utils

not include any business logic

Documentation

Index

Constants

View Source
const (
	Base64Std = iota
	Base64Url
	Base64RawStd
	Base64RawUrl
)
View Source
const StdLen = 16

Variables

View Source
var CurlDebug bool

Functions

func AesDecrypt

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

func AesEncrypt

func AesEncrypt(rawData, key []byte) ([]byte, error)

func AnyToBool

func AnyToBool(raw interface{}) bool

func AnyToFloat64

func AnyToFloat64(raw interface{}) float64

func AnyToInt64

func AnyToInt64(raw interface{}) int64

func AnyToString

func AnyToString(raw interface{}) string

func Base62CusDecode

func Base62CusDecode(str string, baseChar string) uint64

Base62CusDecode 自定义base62解密

func Base62CusEncode

func Base62CusEncode(num uint64, baseChar string) string

Base62CusEncode 自定义base62加密

func Base62Decode

func Base62Decode(str string) uint64

Base62Decode decode str to int

func Base62Encode

func Base62Encode(num uint64) string

Base62Encode encode int to str

func Base64Decode

func Base64Decode(str interface{}, encode int) string

func Base64Encode

func Base64Encode(str interface{}, encode int) string

func Base64RawStdDecode

func Base64RawStdDecode(str interface{}) string

func Base64RawStdEncode

func Base64RawStdEncode(str interface{}) string

func Base64RawUrlDecode

func Base64RawUrlDecode(str interface{}) string

func Base64RawUrlEncode

func Base64RawUrlEncode(str interface{}) string

func Base64StdDecode

func Base64StdDecode(str interface{}) string

func Base64StdEncode

func Base64StdEncode(str interface{}) string

func Base64UrlDecode

func Base64UrlDecode(str interface{}) string

func Base64UrlEncode

func Base64UrlEncode(str interface{}) string

func BoolToStr

func BoolToStr(b bool) string

func ByteToFloat32

func ByteToFloat32(bytes []byte) float32

func ByteToFloat64

func ByteToFloat64(bytes []byte) float64

func BytesToInt64

func BytesToInt64(buf []byte) int64

func BytesToString

func BytesToString(b []byte) string

func CamelToSnake

func CamelToSnake(s string) string

CamelToSnake camel to snake

func CompressDir

func CompressDir(pathToZip, dstPath string) error

func ContainsString

func ContainsString(array []string, val string) (index int)

ContainsString is 字符串是否包含在字符串切片里

func CurlDelete

func CurlDelete(router string, body interface{}, header map[string]string) ([]byte, error)

CurlDelete is curl delete

func CurlGet

func CurlGet(router string, header map[string]string) ([]byte, error)

func CurlPatch

func CurlPatch(router string, body interface{}, header map[string]string) ([]byte, error)

func CurlPost

func CurlPost(router string, body interface{}, header map[string]string) ([]byte, error)

CurlPost only support form and json, BODY support string, []byte, map[string]string

func CurlPostFile

func CurlPostFile(uri string, fields map[string]string, files map[string]string, headers map[string]string) ([]byte, error)

CurlPostFile 以键值对Form表单形式上传文件

func CurlPut

func CurlPut(router string, body interface{}, header map[string]string) ([]byte, error)

func CurlReq

func CurlReq(method, router string, reqBody io.Reader, header map[string]string) (*http.Response, error)

func CustomBase64

func CustomBase64(char ...string) *base64.Encoding

CustomBase64 custom base64 characters

func Debug

func Debug(args ...interface{})

func DeduplicateInt

func DeduplicateInt(ary *[]int)

func DeduplicateInt64

func DeduplicateInt64(ary *[]int64)

func DeduplicateString

func DeduplicateString(ary *[]string)

func DeduplicateUint64

func DeduplicateUint64(ary *[]uint64)

func EmailInit

func EmailInit(addr, identity, user, psw, host, from string)

func EmailSend

func EmailSend(subject, content string, to []string) error

func EmojiCheck

func EmojiCheck(s string) bool

func EmojiFilter

func EmojiFilter(s string) string

func Empty

func Empty(val interface{}) bool

Empty check whether empty

func EnvBool

func EnvBool(key string, def ...bool) bool

func EnvInt

func EnvInt(key string, def ...int) int

func EnvInt64

func EnvInt64(key string, def ...int64) int64

func EnvStr

func EnvStr(key string, def ...string) string

func EnvStrs

func EnvStrs(key string, def ...string) []string

func FileDirCreate

func FileDirCreate(fDir string) error

func FileExist

func FileExist(fpath string) bool

func FileExt

func FileExt(fname string) string

FileExt 获取文件后缀

func FileNameFilter

func FileNameFilter(name string) string

func FilterAlphaNum

func FilterAlphaNum(s string) string

FilterAlphaNum remove not alpha, number and _ characters

func Float32ToByte

func Float32ToByte(float float32) []byte

func Float32ToStr

func Float32ToStr(f float32) string

func Float64ToByte

func Float64ToByte(float float64) []byte

func Float64ToStr

func Float64ToStr(f float64) string

func Float64ToStrPrec1

func Float64ToStrPrec1(f float64) string

func FloatFormat

func FloatFormat(f float64, i int) float64

func FloatToInt64

func FloatToInt64(f float64) int64

func GetBase64Md5

func GetBase64Md5(raw []byte) string

func GetMd5

func GetMd5(raw []byte) string

func HttpBuild

func HttpBuild(body interface{}, sortAsc ...bool) string

func HttpBuildQuery

func HttpBuildQuery(args map[string]string, sortAsc ...bool) string

HttpBuildQuery build request query,sortAsc true为小到大,false为大到小,nil不排序 a=123&b=321

func IPClient

func IPClient(req *http.Request) string

func IPServer

func IPServer() string

func IdDecode

func IdDecode(dst string) (args []uint64)

func IdEncode

func IdEncode(args ...uint64) (dst string)

IdEncode 将一系列ID通过随机数封装起来

func IdInc

func IdInc(s []string) []string

IdInc ID无限增长, 以base62增加,6位为一格, 形式: zzzzzz-zzzzzz-zzzzzz

func Int32ToBytes

func Int32ToBytes(i int32) []byte

func Int64ToBytes

func Int64ToBytes(i int64) []byte

func Int64ToStr

func Int64ToStr(i int64) string

func IntToStr

func IntToStr(i int) string

func JsonDecode

func JsonDecode(data []byte, v interface{}) error

不转义科学计数法

func JsonMarshal

func JsonMarshal(interface{})

func JsonMinify

func JsonMinify(data []byte) []byte

func LvDecode

func LvDecode(data []byte) []byte

func LvDecodeAll

func LvDecodeAll(data []byte) [][]byte

func LvEncode

func LvEncode(data []byte) []byte

func LvEncodeAll

func LvEncodeAll(data [][]byte) (res []byte)

func Map2Struct

func Map2Struct(vals map[string]interface{}, dst interface{}) (err error)

func Map2StructByTag

func Map2StructByTag(vals map[string]interface{}, dst interface{}, structTag string) (err error)

func MaskString

func MaskString(src string, hLen int) string

MaskString change string to abc***def

func Md5

func Md5(str string) string

func Md5Byte

func Md5Byte(b []byte) string

func NetGetLocalIP

func NetGetLocalIP() string

func NetMacAddrs

func NetMacAddrs() (macAddrs []string)

NetMacAddrs get mac

func NetServerIP

func NetServerIP()

NetServerIP get server ip from external

func RandHexHash

func RandHexHash(l int) string

func RandNum

func RandNum(i int) string

func RandStr

func RandStr(l int, c ...string) string

RandStr more random

func RandString

func RandString(length int, chars []byte) string

RandString more fast

func RsaDecrypt

func RsaDecrypt(cipherText, privateKey []byte) ([]byte, error)

解密

func RsaEncrypt

func RsaEncrypt(rawData, publicKey []byte) ([]byte, error)

加密

func RsaKeyGen

func RsaKeyGen(bits int) error

生成私钥文件 TODO 未指定路径

func RsaKeyGenText

func RsaKeyGenText(bits int) (string, string, error)

生成私钥文件, 返回 privateKey , publicKey, error

func Serialize

func Serialize(data interface{}) []byte

func SerializeStr

func SerializeStr(data interface{}, arg ...interface{}) string

func ShuffleSliceBytes

func ShuffleSliceBytes(b []byte)

func ShuffleSliceInt

func ShuffleSliceInt(i []int)

func ShuffleSliceInterface

func ShuffleSliceInterface(i []interface{})

func ShuffleString

func ShuffleString(s *string)

func SlashAdd

func SlashAdd(s string) string

func SlashDel

func SlashDel(s string) string

func Slice2String

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

zero copy to change slice to string

func SliceJoin

func SliceJoin(sep string, elems ...interface{}) string

任意slice合并

func SliceStringToUint64

func SliceStringToUint64(s []string) (i []uint64)

func SnakeToCamel

func SnakeToCamel(s string) string

SnakeToCamel snake to camel

func SplitZero

func SplitZero(s string) (string, string)

SplitZero 拆分一个0阻隔, split zero from string

func SqlErrDuplicate

func SqlErrDuplicate(err error) bool

func SqlErrNil

func SqlErrNil(err error) bool

func SqlErrNoRow

func SqlErrNoRow(err error) bool

func SqlIn

func SqlIn(raw interface{}) string

func SqlInSlice

func SqlInSlice(raw interface{}) string

SqlInSlice is same with SqlIn, and faster than SqlIn

func StrToBool

func StrToBool(s string) bool

func StrToFloat32

func StrToFloat32(s string) float32

func StrToFloat64

func StrToFloat64(s string) float64

func StrToInt

func StrToInt(s string) int

func StrToInt64

func StrToInt64(s string) int64

func StrToTime

func StrToTime(s string) (int64, error)

func StrToUint64

func StrToUint64(s string) uint64

func StringReplace

func StringReplace(s string, old, new []string) string

func StringToBytes

func StringToBytes(s string) []byte

func StringToSlice

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

no copy to change string to slice

func StringsBatchReplace

func StringsBatchReplace(s string, old, new []string) (string, error)

批量字符串替换

func Struct2Map

func Struct2Map(s interface{}) map[string]interface{}

func Struct2MapByTag

func Struct2MapByTag(s interface{}, tagName string) map[string]interface{}

func TempGet

func TempGet(name string) (interface{}, error)

TempGet os temp dir get

func TempSet

func TempSet(name string, data interface{}) error

TempSet 系统临时文件夹存取

func TimeFmtNanoUnix

func TimeFmtNanoUnix() string

func TimeHmsToUnix

func TimeHmsToUnix(str string) (int64, error)

时分秒字符串转时间戳,传入示例:8:40 or 8:40:10

func TimeInterval

func TimeInterval(unit string, amount int) (startTime, endTime int64)

获取一个当前时间 时间间隔 时间戳

func TimeParse

func TimeParse(format, src string) (time.Time, error)

func TimeParseStd

func TimeParseStd(src string) time.Time

func TimeShortStr

func TimeShortStr() string

func TimeStdParseUnix

func TimeStdParseUnix(src string) int64

func TimeStdStr

func TimeStdStr() string

func TimeToStr

func TimeToStr(unixSecTime interface{}, layout ...string) string

func TlvDecode

func TlvDecode(data []byte) (tag uint8, b []byte)

func TlvEncode

func TlvEncode(tag uint8, data []byte) []byte

func ToByte

func ToByte(raw interface{}, e error) []byte

func ToInt64

func ToInt64(raw interface{}, e error) int64

func ToString

func ToString(raw interface{}, e error) (res string)

func UUID

func UUID() string

func Uint64ToBytes

func Uint64ToBytes(i uint64) []byte

func Uint64ToStr

func Uint64ToStr(i uint64) string

func Unserialize

func Unserialize(b []byte, dst interface{})

func ValidateChinaPhone

func ValidateChinaPhone(phone string) bool

func ValidateEmail

func ValidateEmail(email string) bool

Types

type AesCrypt

type AesCrypt struct {
	Key []byte
	Iv  []byte
}

AesCrypt this struct can customize 'IV' instead of using key size be the IV NOTICE: iv length must equal key block size

func (*AesCrypt) Decrypt

func (a *AesCrypt) Decrypt(src []byte) (data []byte, err error)

func (*AesCrypt) Encrypt

func (a *AesCrypt) Encrypt(data []byte) ([]byte, error)

type TagValue

type TagValue struct {
	Tag   uint8
	Value []byte
}

func TlvDecodeAll

func TlvDecodeAll(data []byte) []*TagValue

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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