util

package
v1.8.7 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: Apache-2.0 Imports: 40 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"
)

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

func BytesToStr

func BytesToStr(b []byte) string

func CheckFileIsExist

func CheckFileIsExist(filename string) bool

func CheckNotNil

func CheckNotNil(r *http.Request, args ...string) error

CheckNotNil 检查HTTP参数是否为空

func CheckParam

func CheckParam(hr *http.Request, args ...string) string

检查http请求中是否包含所需参数 Deprecated: 使用CheckNotNil代替

func CheckRemoteIP

func CheckRemoteIP(r *http.Request, ips ...string) bool

CheckRemoteIP 验证IP in ips return true

func ClientIP

func ClientIP(r *http.Request) string

ClientIP 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func ClientPublicIP

func ClientPublicIP(r *http.Request) string

ClientPublicIP 尽最大努力实现获取客户端公网 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

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 CtxFormIntDefault

func CtxFormIntDefault(ctx *fiber.Ctx, key string, def int) int

FormIntDefault 获取Form参数 如果出错则返回默认值

func CtxGetURL

func CtxGetURL(URL string) ([]byte, error)

GetURL 请求URL

func CtxGetURLReceiveJSON

func CtxGetURLReceiveJSON(URL string, params url.Values, receive interface{}) error

func CtxGetValueURL

func CtxGetValueURL(URL string, params url.Values) ([]byte, error)

func DoURL

func DoURL(method, url string, body []byte) ([]byte, error)

DoURL 请求URL并且解析JSON格式的返回数据

func ECBDecrypt

func ECBDecrypt(crypted []byte, keyStr string) ([]byte, error)

ECB模式解密

func ECBEncrypt

func ECBEncrypt(srcStr, keyStr string) ([]byte, error)

ECB模式加密

func FilterMysqlNilErr

func FilterMysqlNilErr(err error) bool

func FilterRedisNilErr

func FilterRedisNilErr(err error) bool

func FormFileValue

func FormFileValue(r *http.Request, key string) (string, error)

FormFileValue 快速获取表单提交的文件 也用于处理同表单一起提交的信息

func FormFileValues

func FormFileValues(r *http.Request, key string) ([]string, error)

FormFileValues 快速获取表单提交的文件 也用于处理同表单一起提交的信息

func FormIntDefault

func FormIntDefault(r *http.Request, key string, def int) int

FormIntDefault 获取Form参数 如果出错则返回默认值

func FormIntSliceDefault

func FormIntSliceDefault(r *http.Request, key, sep string, def []int) []int

FormIntSliceDefault 获取Form参数 如果出错则返回默认值

func GbkToUtf8

func GbkToUtf8(gbkData []byte) []byte

func GetCurrentDirectory

func GetCurrentDirectory() string

func GetIp

func GetIp(r *http.Request) string

func GetJSON

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

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

func GetParentDirectory

func GetParentDirectory(dirctory string) string

func GetRemoteIP

func GetRemoteIP(r *http.Request) string

GetRemoteIP 获取IP

func GetToken

func GetToken(ctx *fiber.Ctx) (token string)

func GetURL

func GetURL(URL string) ([]byte, error)

GetURL 请求URL

func GetURLReceiveJSON

func GetURLReceiveJSON(URL string, params url.Values, receive interface{}) error

GetURLReceiveJSON GET请求 自动解析JSON

func GetUUid

func GetUUid() string

func GetValueURL

func GetValueURL(URL string, params url.Values) ([]byte, error)

GetValueURL 请求URL 附带参数

func GzipCompress

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

func GzipUnCompress

func GzipUnCompress(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 HasLocalIP

func HasLocalIP(ip net.IP) bool

HasLocalIP 检测 IP 地址是否是内网地址 通过直接对比ip段范围效率更高,详见:https://github.com/thinkeridea/go-extend/issues/2

func HasLocalIPddr

func HasLocalIPddr(ip string) bool

HasLocalIPddr 检测 IP 地址字符串是否是内网地址

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 IP2Long

func IP2Long(ip net.IP) (uint, error)

IP2Long 把net.IP转为数值

func IPString2Long

func IPString2Long(ip string) (uint, error)

IPString2Long 把ip字符串转为数值

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 IsSameDay

func IsSameDay(oldDay, anotherDay int64) bool

*

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

func IsUtf8

func IsUtf8(data []byte) bool

func IsValidIPv4

func IsValidIPv4(ip string) bool

IsValidIPv4 验证是否为合法的ipv4

func JoinInt

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

func LoadJSONConfig

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

LoadJSONConfig 读取配置文件 json格式

func Long2IP

func Long2IP(i uint) (net.IP, error)

Long2IP 把数值转为net.IP

func Long2IPString

func Long2IPString(i uint) (string, error)

Long2IPString 把数值转为ip字符串

func MD5Hash

func MD5Hash(b []byte) []byte

MD5Hash md5

func MD5HexHash

func MD5HexHash(b []byte) string

MD5HexHash md5 and encode to string

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 PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

PKCS5填充

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) ([]byte, error)

去除PKCS5填充

func PostJSON

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

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

func PostJSONReceiveJSON

func PostJSONReceiveJSON(URL string, send, receive interface{}) error

PostJSONReceiveJSON POST请求 BODY为JSON格式 ContentType=application/json 自动解析JSON

func PostMapReceiveJSON

func PostMapReceiveJSON(URL string, maps map[string]string, receive interface{}) error

PostURLReceiveJSON POST请求 自动解析JSON

func PostToJSON

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

PostToJSON POST请求 BODY为json格式 Deprecated: Please use PostJSON to replace

func PostURL

func PostURL(URL string, params url.Values) ([]byte, error)

PostURL 请求URL

func PostURLReceiveJSON

func PostURLReceiveJSON(URL string, params url.Values, receive interface{}) error

PostURLReceiveJSON POST请求 自动解析JSON

func PwdDecode

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

func PwdEncode

func PwdEncode(pwd string, key string) string

func RemoteIP

func RemoteIP(r *http.Request) string

RemoteIP 通过 RemoteAddr 获取 IP 地址, 只是一个快速解析方法。

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 Str2bytes

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

替换string与byte转换时性能损耗的代码 !!! 只可用于不可修改字符串变量

func StrToBytes

func StrToBytes(s string) []byte

func StringIsEmpty

func StringIsEmpty(s ...string) bool

StringIsEmpty 判断是否有值为空或null或(null)

func Substr

func Substr(str string, start, length int) string

func WriteJSON

func WriteJSON(w io.Writer, v interface{}) (int, error)

WriteJSON 写入json字符串

Types

type Map

type Map map[string]interface{}

Jump to

Keyboard shortcuts

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