utils

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PaddingTypePKCS7 = iota // 推荐使用
	PaddingTypePKCS5
	PaddingTypeZero      // 不推荐使用
	PaddingTypeNoPadding // 不要用
)

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string without a memory allocation.

func CompareSortedStrings

func CompareSortedStrings(lhs, rhs []string) bool

比较已经排序好的字符串切片

func Copy

func Copy(toValue interface{}, fromValue interface{}) (err error)

Copy copy things

func DecryptDesEcb

func DecryptDesEcb(src, key string, paddingType int) (d string, err error)

ECB解密, 使用PKCS7进行填充

func DiffStrings

func DiffStrings(oldStrings, newStrings []string) ([]string, []string)

return adds, dels

func EncryptDesEcb

func EncryptDesEcb(src, key string, paddingType int) (e string, err error)

ECB加密, 使用PKCS7进行填充

func Exists

func Exists(path string) bool

判断文件或目录是否存在

func FileSize

func FileSize(file string) (int64, error)

func Format

func Format(format string, t time.Time) string

Format 格式化时间 This is an alternative to time.Format because no one knows what date 040305 is supposed to create when used as a 'layout' string this takes standard strftime format options. For a complete list of format options see http://strftime.org/

func GenUUID

func GenUUID() string

获取 uuid

func GetClientIp

func GetClientIp(ctx *gin.Context) string

过 ingress 的请求clientIp 优先从 "X-Original-Forwarded-For" 中获取

func GetFormatRequestTime

func GetFormatRequestTime(time time.Time) string

func GetFunctionName

func GetFunctionName(i interface{}, seps ...rune) string

获取函数名称

func GetHandler

func GetHandler(ctx *gin.Context) (handler string)

func GetLocalIp

func GetLocalIp() string

获取本机ip

func GetRequestCost

func GetRequestCost(start, end time.Time) float64

func GetUuidString

func GetUuidString() string

func GetUuidUInt64

func GetUuidUInt64() uint64

func HashInt

func HashInt(s string) int64

将传入字符转换成数字的hash算法(兼容odp)

func Int64sContain

func Int64sContain(a []int64, x int64) bool

func IntStringContain

func IntStringContain(a []string, x string) bool

func IsExist

func IsExist(path string) bool

func IsJsonMap

func IsJsonMap(s string) bool

func IsJsonSlice

func IsJsonSlice(s string) bool

func IsJsonString

func IsJsonString(s string) bool

func JoinArgs

func JoinArgs(showByte int, args ...interface{}) string

func LoadConf

func LoadConf(path string, cf interface{}) bool

func LoadFile

func LoadFile(path string) ([]byte, bool)

func Md5

func Md5(plain string) string

单向加密算法

func MultiJoinString

func MultiJoinString(str ...string) string

func PKCS5Padding

func PKCS5Padding(cipherText []byte) []byte

PKCS7Padding的子集,块大小固定为8字节

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

func PKCS7Padding

func PKCS7Padding(cipherText []byte, blockSize int) []byte

假设数据长度需要填充n(n>0)个字节才对齐,那么填充n个字节,每个字节都是n; 如果数据本身就已经对齐了,则填充一块长度为块大小的数据,每个字节都是块大小

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

func RandNum

func RandNum(num ...int) int

func Rc4Decode

func Rc4Decode(key, encrypted string) (string, error)

func Rc4DecodeBytes

func Rc4DecodeBytes(key []byte, encrypted string) ([]byte, error)

func Rc4Encode

func Rc4Encode(key, plainText string) (string, error)

func Rc4EncodeBytes

func Rc4EncodeBytes(key, plainText []byte) (string, error)

func SHA1

func SHA1()

func SHA256

func SHA256()

func SaveConf

func SaveConf(conf interface{}, path string) bool

func StrToUint

func StrToUint(strNumber string, value interface{}) error

func StringToBytes

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

StringToBytes converts string to byte slice without a memory allocation.

func StructToMap

func StructToMap(obj interface{}) map[string]interface{}

func UnmarshalJson

func UnmarshalJson(jsonVal []byte, objVal interface{}) error

func ZeroPadding

func ZeroPadding(cipherText []byte, blockSize int) []byte

ZeroPadding,数据长度不对齐时使用0填充,否则不填充 只适合以\0结尾的字符串加解密

func ZeroUnPadding

func ZeroUnPadding(origData []byte) []byte

Types

type BufferPool

type BufferPool struct {
	sync.Pool
}

func NewBufferPool

func NewBufferPool(bufferSize int) (bufferpool *BufferPool)

声明一块buffer pool大小

func (*BufferPool) Get

func (bufferpool *BufferPool) Get() *bytes.Buffer

获取一块buffer写入

func (*BufferPool) Put

func (bufferpool *BufferPool) Put(b *bytes.Buffer)

放回buffer重用

type Conf

type Conf struct {
	*viper.Viper
	Name string
	Data interface{}
}

func Load

func Load(name string, data interface{}) (*Conf, error)

func (*Conf) Sub

func (conf *Conf) Sub(key string) *Conf

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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