toolfunc

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB int64 = 1 << (10 * iota)
	MB
	GB
	TB
)

将KB、MB、GB和TB转换为字节的

Variables

View Source
var PwdKey = []byte("1234asdf1234asdf")

16,24,32位字符串的话,分别对应AES-128,AES-192,AES-256 加密方法 key不能泄露

Functions

func AesDecrypt

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

AesDecrypt 解密

func AesEncrypt

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

AesEncrypt 加密

func BigFileMd5

func BigFileMd5(path string) (string, error)

func BinaryFind

func BinaryFind(arrslice []int64, findvalue int64) int

func BubbleSortPro

func BubbleSortPro(arr []int64) []int64

func BuildURL

func BuildURL(prefix string, params ...interface{}) (urlstr string)

生成url链接

prefix              前缀
params              参数

@return urlstr 返回组装后的url

func CalcInt

func CalcInt(num1 interface{}, oper string, num2 interface{}) int

整型计算

func CheckFileIsExist

func CheckFileIsExist(filename string) bool

func CheckFileName

func CheckFileName(fileName string) error

CheckFileName ***

func CheckFileType

func CheckFileType(allSupportedType []string, fileName string) error

CheckFileType ***

func CheckInterface

func CheckInterface(inter interface{})

func CheckName

func CheckName(fileName string) error

func CompressSvg

func CompressSvg(file string) (err error)

压缩svg文件

file			需要压缩的svg文件

@return err 错误

func ComputeFileMD5

func ComputeFileMD5(file io.Reader) string

func ConvertToYuan

func ConvertToYuan(amount float64, unit string, decimalPlaces int) (float64, string)

ConvertToYuan 将金额转换为匹配的单位

func CreateCaptcha

func CreateCaptcha(n int) string

CreateCaptcha 生成随机数 n:生成的位数

func DataString2Time

func DataString2Time(str string, format ...string) time.Time

func Decimal

func Decimal(value float64) float64

func DecodeURI

func DecodeURI(encoded string) (string, error)

DecodeURI ***

func DecryptByAes

func DecryptByAes(data string, key []byte) ([]byte, error)

DecryptByAes base64解码后 Aes 解密

func DeleteSlice

func DeleteSlice(slice []string, keys ...string) []string

删除切片中的指定key,并返回

func DetermineUnit

func DetermineUnit(amount float64) string

DetermineUnit 根据金额的大小确定单位(元、万元、亿)

func EncUserPwd

func EncUserPwd(password, salt string) (hash string)

用户密码加密

func EncodeURI

func EncodeURI(rawString string) string

EncodeURI ***

func EncryptByAes

func EncryptByAes(data []byte, key []byte) (string, error)

EncryptByAes Aes加密 后 base64

func Equal

func Equal(itf1, itf2 interface{}) bool

比较两个内容的字符串类型是否相等

func FileMd5

func FileMd5(path string) (string, error)

获取文件的MD5 @path string 文件路径

func FirstMonday

func FirstMonday(year int, month time.Month) int

当月第一个周一

func GenerateInt64 added in v1.2.7

func GenerateInt64() int64

func GenerateSalt

func GenerateSalt() (salt string)

随机生成7位的盐值

func GenerateUUID

func GenerateUUID() string

func GetDays

func GetDays(start, end int64) (timeSilce []string)

func GetDuration

func GetDuration(start, end int64) int

func GetFileExt

func GetFileExt(fileName string) string

func GetFirstDateOfWeek

func GetFirstDateOfWeek() (weekMonday string)

func GetHourDiffer

func GetHourDiffer(start_time, end_time string) int64

func GetLastWeekFirstDate

func GetLastWeekFirstDate() (weekMonday string)

* 获取上周的周一日期

func GetNextWeekFirstDate

func GetNextWeekFirstDate() (weekMonday string)

func GetNextWeekLastDate

func GetNextWeekLastDate() (weekMonday string)

func GetSuffix

func GetSuffix(str, seg string) string

根据字符串后缀,比如根据文件路径获取后缀等 @str string 字符串或者文件路径 @seg string 分隔符

func HeightLight

func HeightLight(title string, words []string) template.HTML

高亮,主要用于搜索结果高亮

func HtmlToMarkdown

func HtmlToMarkdown(html string) (string, error)

func HttpPost

func HttpPost(url, token string, parMap interface{}) (map[string]interface{}, error)

----------------------------------------------------------------------

func Int2Int64

func Int2Int64(a int) int64

func Int2String

func Int2String(a int) string

func Int642String

func Int642String(a int64) string

func Interface2Int

func Interface2Int(a interface{}) int

将字符串或者其他可转化数字的内容格式化成int数字类型返回

a            interface{}         需要转化成数字的内容

func Interface2Int64

func Interface2Int64(a interface{}) int64

func Interface2String

func Interface2String(v interface{}) string

将interface{}转为字符串,适合bool,数字等 @v interface{} 需要转化为字符串的值

func IsChinese

func IsChinese(str string) bool

func IsImage

func IsImage(path string) bool

判断文件路径判断文件是否是符合要求的图片格式,jpeg,jpg,gif,png,bmp,tif,tiff @path string 文件路径

func LocalTransUTC

func LocalTransUTC(localTime string) string

func MyMD5

func MyMD5(str string) string

func NumberOfNowWeekInMonth added in v1.2.5

func NumberOfNowWeekInMonth() int

判断第几周

func NumberOfWeekInMonth

func NumberOfWeekInMonth(t time.Time) int

判断第几周

func NumberRange

func NumberRange(val, min, max int) int

数字变化范围

val             int         需要处理的参数数字
min             int         最小值
max             int         最大值

@return int 返回最大值与最小值之间的值

func RemoveDuplicateElement

func RemoveDuplicateElement(addrs []string) []string

func RemoveDuplicateIntElement

func RemoveDuplicateIntElement(addrs []int) []int

func RemoveDuplicateUintElement

func RemoveDuplicateUintElement(addrs []uint) []uint

func RemoveRepeatedElement

func RemoveRepeatedElement(tags string) (newtags string)

func Sha1Enc

func Sha1Enc(s string) string

func StarVal

func StarVal(score int, IsScore bool) string

文档评分处理 score:文档评分 IsScore:是否返回处理后的评分,true:返回评分,如“4.5”,false返回css的星,如"45"

func String2Int

func String2Int(a string) int

func String2Int64

func String2Int64(a string) int64

func String2Time

func String2Time(str string, format ...string) time.Time

字符串转时间格式 @str string 时间字符串 @format string 时间格式,如:"2006-01-02 15:04:05"

func StringIn

func StringIn(target string, str_array []string) bool

func StringListToIntList

func StringListToIntList(src []string) (dest []int)

func StringSliceToInterfaceSlice

func StringSliceToInterfaceSlice(slice []string) (ret []interface{})

将字符串切片转成interface切片

func StringSliceToMap

func StringSliceToMap(slice []string) (maps map[string]string)

将字符串切片数组转成map

func Struct2Map

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

func Strval2String

func Strval2String(value interface{}) string

func SubStr

func SubStr(str interface{}, start, length int) string

字符串截取

func TimestampFormat

func TimestampFormat(timestamp int64, format ...string) string

时间戳格式化 @timestamp int 时间戳 @format string 时间格式,如:"2006-01-02 15:04:05"

func ToBytes added in v1.3.1

func ToBytes(size int64, unit string) int64

size是数值,uint是单位

func ToInterfaceSlice

func ToInterfaceSlice(slice interface{}) []interface{}

func TwoDifference

func TwoDifference(slice1, slice2 []int) []int

求差集 slice1-并集

func TwoIntersect

func TwoIntersect(slice1, slice2 []int) []int

求交集

func TwoUnion

func TwoUnion(slice1, slice2 []int) []int

求并集

func UTCTransLocal

func UTCTransLocal(utcTime string) string

func Uint2String

func Uint2String(a uint) string

func Uint642String

func Uint642String(a uint64) string

func UndifinedTimeToStr

func UndifinedTimeToStr(t1 string) time.Time

func UniqueSort

func UniqueSort(slice []int64) []int64

func Unzip

func Unzip(zipFile string, destDir string) error

func UpperFirst

func UpperFirst(str string) string

首字母大写

func UrlEscape

func UrlEscape(str string) string

url请求处理

func UserMD5

func UserMD5(usr string, pwd string, salt string) string

MD5加密函数 @str string 需要进行加密的字符串

func WhichWeekDay

func WhichWeekDay() int

判断星期几

func Xmd5

func Xmd5(md5str interface{}) string

xmd5加密,扩展加密

md5str          MD5字符串

func Zip

func Zip(srcFile string, destZip string) error

Types

type EscapeError

type EscapeError string

EscapeError ***

func (EscapeError) Error

func (e EscapeError) Error() string

type Headers

type Headers struct {
	Header req.Header // = make(Header)
}

Headers ***

func NewHeaders

func NewHeaders() *Headers

NewHeaders ***

func (*Headers) AddBasicAuthHeader

func (o *Headers) AddBasicAuthHeader(appKey string, appSecret string)

AddBasicAuthHeader ***

func (*Headers) AddOAuth2Header

func (o *Headers) AddOAuth2Header(token string)

AddOAuth2Header ***

type Info

type Info struct {
	Width, Height int    //图片宽高
	Size          int64  //图片文件大小
	Md5           string //图片md5
	ModTime       int    //图片修改时间戳
	Ext           string //图片后缀
}

图片文件信息

type ServiceClient

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

ServiceClient ***

func NewServiceClient

func NewServiceClient() *ServiceClient

NewServiceClient ***

func (*ServiceClient) Delete

func (o *ServiceClient) Delete(url string, v ...interface{}) *req.Resp

Delete ***

func (*ServiceClient) Get

func (o *ServiceClient) Get(url string, v ...interface{}) *req.Resp

Get ***

func (*ServiceClient) Head

func (o *ServiceClient) Head(url string, v ...interface{}) *req.Resp

Head ***

func (*ServiceClient) Post

func (o *ServiceClient) Post(url string, v ...interface{}) *req.Resp

Post ***

func (*ServiceClient) Put

func (o *ServiceClient) Put(url string, v ...interface{}) *req.Resp

Put ***

Jump to

Keyboard shortcuts

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