util

package
v0.0.0-...-9337120 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

辅助工具层

Index

Constants

View Source
const (
	TimeFormat     = "2006-01-02 15:04:05"
	TimeFormatDay  = "20060102"
	TimeFormatDay2 = "2006-01-02"
	TimeFormatDay3 = "2006/01/02"
	TimeFormatDay4 = "2006.01.02_15"
)

Variables

View Source
var TokenBucket sync.Map

Functions

func AesDecryptCBC

func AesDecryptCBC(encrypted []byte, key []byte) (decrypted []byte)

func AesEncryptCBC

func AesEncryptCBC(origData []byte, key []byte) (encrypted []byte)

=================== CBC ======================

func Bytes2str

func Bytes2str(b []byte) string

b2s converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .

Note it may break if string and/or slice header will change in the future go versions.

func BytesToStr

func BytesToStr(b []byte) string

func CreateAnyTypeSlice

func CreateAnyTypeSlice(slice interface{}) ([]interface{}, bool)

interface{}转为 []interface{}

func CtxClientIP

func CtxClientIP(ctx *fasthttp.RequestCtx) string

获取真实的IP 1.1.1.1, 2.2.2.2, 3.3.3.3

func FilterMysqlNilErr

func FilterMysqlNilErr(err error) bool

func FilterRedisNilErr

func FilterRedisNilErr(err error) bool

func GbkToUtf8

func GbkToUtf8(gbkData []byte) []byte

func GetCurrentDirectory

func GetCurrentDirectory() string

func GetParentDirectory

func GetParentDirectory(dirctory string) string

func GetToken

func GetToken(ctx *Ctx) (token string)

func GetUUid

func GetUUid() string

func GzipCompress

func GzipCompress(data string) ([]byte, error)

func GzipCompressByte

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

func GzipUnCompress

func GzipUnCompress(data []byte) (string, error)

func GzipUnCompressByte

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

func HMACSHA1Hash

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

HMACSHA1Hash hmac-sha1

func HMACSHA1HexHash

func HMACSHA1HexHash(src, key []byte) string

HMACSHA1HexHash hmac-sha1 and encode to string

func Hash

func Hash(ht crypto.Hash, b []byte) []byte

Hash 散列函数 返回空值则为错误

func HashHex

func HashHex(ht crypto.Hash, b []byte) string

HashHex can hash and encode to string

func HmacSha256

func HmacSha256(data string, secret string) string

func InArr

func InArr(array []int, column int) bool

func InMap

func InMap(maps map[string]int, column string) (ok bool)

func InstrArr

func InstrArr(array []string, column string) bool

func IsGBK

func IsGBK(data []byte) bool

func IsJson

func IsJson(str string) bool

func IsMysqlRepeatError

func IsMysqlRepeatError(err error) bool

func IsSameDay

func IsSameDay(oldDay, anotherDay int64) bool

*

  • 二个时间戳是否同一天
  • @return true 是 false 不是今天

func IsUtf8

func IsUtf8(data []byte) bool

func JoinInt

func JoinInt(s []int, sp string) string

func LoadJSONConfig

func LoadJSONConfig(filename string, v interface{}) error

LoadJSONConfig 读取配置文件 json格式

func MD5Hash

func MD5Hash(b []byte) []byte

MD5Hash md5

func MD5HexHash

func MD5HexHash(b []byte) string

MD5HexHash md5 and encode to string

func Model2Map

func Model2Map(m interface{}, needZeroByInt, needZeroByString bool) (res map[string]interface{})

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.

func OpenWinBrowser

func OpenWinBrowser(uri string) error

func PostJSON

func PostJSON(URL string, v interface{}) ([]byte, error)

PostJSON POST请求 BODY为JSON格式 ContentType=application/json

func PwdDecode

func PwdDecode(pwd string, key string) (string, error)

func PwdEncode

func PwdEncode(pwd string, key string) string

func RemoveRepeatedElement

func RemoveRepeatedElement(arr []string) (newArr []interface{})

func SHA1HexHash

func SHA1HexHash(b []byte) string

SHA1HexHash sha1 and encode to string

func SHA256HexHash

func SHA256HexHash(b []byte) string

SHA256HexHash sha256 and encode to string

func SplitInt

func SplitInt(s, sep string) ([]int, error)

SplitInt 分割字符串并转为INT

func Str2Time

func Str2Time(formatTimeStr, timeFormat string) time.Time

*字符串->时间对象

func Str2bytes

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

s2b converts string to a byte slice without memory allocation.

Note it may break if string and/or slice header will change in the future go versions.

func StrToBytes

func StrToBytes(s string) []byte

func WriteJSON

func WriteJSON(ctx *fasthttp.RequestCtx, v interface{}) error

WriteJSON 写入json字符串

Types

type Set

type Set struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSet

func NewSet() *Set

func (*Set) Add

func (s *Set) Add(item interface{})

func (*Set) Clear

func (s *Set) Clear()

func (*Set) Has

func (s *Set) Has(item interface{}) bool

func (*Set) IsEmpty

func (s *Set) IsEmpty() bool

func (*Set) Len

func (s *Set) Len() int

func (*Set) List

func (s *Set) List() []interface{}

func (*Set) Remove

func (s *Set) Remove(item interface{})

type Tutil

type Tutil struct {
	// contains filtered or unexported fields
}

func NewTutil

func NewTutil(tagP string, logFloag bool, logger *zap.Logger) *Tutil

func (*Tutil) EndT

func (this *Tutil) EndT(tagC string, haveNext ...bool)

Jump to

Keyboard shortcuts

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