utils

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2022 License: Apache-2.0 Imports: 29 Imported by: 2

Documentation

Index

Constants

View Source
const (
	NUmStr  = "0123456789"
	CharStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
	SpecStr = "+=-@#~,.[]()!%^*$"
)

Variables

View Source
var ArrType = reflect.TypeOf([]interface{}{})
View Source
var MapType = reflect.TypeOf(map[string]interface{}{})

Functions

func AESDecrypt

func AESDecrypt(src, key string) string

* key :either 16, 24, or 32 bytes to select

func AESEncrypt

func AESEncrypt(src, key string) string

* key :either 16, 24, or 32 bytes to select

func AesDecrypt

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

* key :either 16, 24, or 32 bytes to select

func AesEncrypt

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

* key :either 16, 24, or 32 bytes to select

func AppendFloatToCsv

func AppendFloatToCsv(filename string, row []float64)

func AppendFloatsToCsv

func AppendFloatsToCsv(filename string, rows [][]float64)

func AppendToCsv

func AppendToCsv(filename string, row []string)

func AppendsToCsv

func AppendsToCsv(filename string, rows [][]string)

func ArrayContains

func ArrayContains(arr []string, s string) bool

func Clone added in v0.1.6

func Clone(src interface{}) interface{}

浅克隆,可以克隆任意数据类型,对指针类型子元素无法克隆 获取类型:如果类型是指针类型,需要使用Elem()获取对象实际类型 获取实际值:如果值是指针类型,需要使用Elem()获取实际数据 说白了,Elem()就是获取反射数据的实际类型和实际值

func CompareInter

func CompareInter(a, b interface{})

func CompareInterface

func CompareInterface(key string, a, b interface{}) (bool, interface{}, interface{})

func DESDecrypt

func DESDecrypt(src, key string) string

* key 必须是8位

func DESEncrypt

func DESEncrypt(src, key string) string

* key 必须是8位

func DecryptDES

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

func DeepClone added in v0.1.6

func DeepClone(src interface{}) (error, interface{})

深度克隆,可以克隆任意数据类型

func EncryptDES

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

func ExternalIP

func ExternalIP() (net.IP, error)

func Float32ToString

func Float32ToString(input_num float32) string

float32 转 String工具类,保留6位小数

func Float64ToStr

func Float64ToStr(input_num float64, prec int) string

func Float64ToString

func Float64ToString(input_num float64) string

func Float64sToStrings

func Float64sToStrings(input_nums []float64) []string

func GenerateRSAKey

func GenerateRSAKey(bits int)

生成RSA私钥和公钥,保存到文件中 bits 证书大小

func Get

func Get(url string) (response string)

发送GET请求 url:请求地址 response:请求返回的内容

func GetTag added in v0.1.8

func GetTag(u interface{}, key string) string

func GetYYYYMMDD

func GetYYYYMMDD() string

func GetYYYYMMDDHHMMSS

func GetYYYYMMDDHHMMSS() string

func If

func If(condition bool, trueValue, falseValue interface{}) interface{}

func Int64ToStr

func Int64ToStr(num int64) string

int64到string

func JsonBytesToStruct

func JsonBytesToStruct(jsonByte []byte, result interface{})

参数result必须是指针

func JsonToMap

func JsonToMap(jsonStr string, mapResult map[string]interface{})

func JsonToStruct

func JsonToStruct(jsonStr string, result interface{})

参数result必须是指针

func MapToJson

func MapToJson(instance interface{}) string

func MapToStruct

func MapToStruct(m interface{}, s interface{}) error

参数s必须是指针

func MapToStruct2

func MapToStruct2(m interface{}, s interface{}) error

func Md5

func Md5(s string) string

md5加密

func NewFixedDelayJob

func NewFixedDelayJob(d time.Duration, f func())

func NewInterface added in v0.1.6

func NewInterface(typ reflect.Type, data []byte) (error, interface{})

func PKCS5Padding

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

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

func Post

func Post(url string, data interface{}, contentType string) (content string)

发送POST请求 url:请求地址,data:POST请求提交的数据,contentType:请求体格式,如:application/json content:请求放回的内容

func RSADecrypt

func RSADecrypt(text string, rsaPrivateKey string) string

RSADecrypt RSA解密 cipherText 需要解密的byte数据 rsaPrivateKey 私钥

func RSAEncrypt

func RSAEncrypt(text string, rsaPublicKey string) string

RSAEncrypt RSA加密 plainText 要加密的数据 path 公钥

func Random

func Random(start float64, end float64) float64

func RandomPassword

func RandomPassword(passwordLength int, charset string) string

RandomPassword 随机生成密码 参数说明:

length: 生成密码的长度
charset:
  num:只使用数字[0-9],
  char:只使用英文字母[a-zA-Z],
  mix:使用数字和字母,
  advance:使用数字、字母以及特殊字符

如:RandomPassword(16, "mix")

->  bJZSD6YpSAvDM6DY

func ReadFileLast

func ReadFileLast(filename string, readChannel chan string)

func ReadFromCsv

func ReadFromCsv(filename string) [][]string

func SaveToCsv

func SaveToCsv(filename string, rows [][]string)

func SaveToFile

func SaveToFile(filename string, context string)

func Sha256

func Sha256(s string) string

Sha256加密

func SortArrMap added in v0.1.6

func SortArrMap(maps []map[string]interface{}, by func(a, b map[string]interface{}) bool)

func SortBodyByCreateTime added in v0.1.6

func SortBodyByCreateTime(arr []interface{})

按照createtime排序,需要注意是否有createtime

func SortInterface added in v0.1.6

func SortInterface(arr []interface{}, by func(p, q *interface{}) bool)

自定义排序字段,参考SortBodyByCreateTime中的传入函数

func StrArr2ToFloat

func StrArr2ToFloat(arr *[][]interface{})

func StrArr2ToFloatArr2

func StrArr2ToFloatArr2(arr [][]string) [][]float64

func StrToBool

func StrToBool(inputValue string) bool

func StrToBoolDef

func StrToBoolDef(inputValue string, defValue bool) bool

func StrToFloat64

func StrToFloat64(input_num string) float64

func StrToFloat64Def

func StrToFloat64Def(input_num string, defValue float64) float64

func StrToInt

func StrToInt(input_num string) int

func StrToInt64

func StrToInt64(input_num string) int64

string到int64

func StrToInt64Def

func StrToInt64Def(inputValue string, defValue int64) int64

func StrToIntDef

func StrToIntDef(input_num string, defValue int) int

func StrToUint64

func StrToUint64(input_num string) uint64

string到uint64

func StrToUint64Def

func StrToUint64Def(inputValue string, defValue uint64) uint64

func StructToJson

func StructToJson(result interface{}) string

func StructToMap

func StructToMap(s interface{}, m interface{}) error

参数m必须是指针

func SubstrAfter

func SubstrAfter(s, substr string) string

func SubstrBefore

func SubstrBefore(s, substr string) string

func SubstrBetween

func SubstrBetween(s, afterStr, beforeStr string) string

func Substring

func Substring(source string, start int, end int) string

获取source的子串,如果start小于0或者end大于source长度则返回"" start:开始index,从0开始,包括0 end:结束index,以end结束,但不包括end

func TimeToStr

func TimeToStr(t time.Time) string

func Uint64ToStr

func Uint64ToStr(num uint64) string

uint64到string

func UtcToTime

func UtcToTime(utcDate string) time.Time

Types

This section is empty.

Jump to

Keyboard shortcuts

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