until

package module
v0.0.0-...-98e0aed Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: MIT Imports: 38 Imported by: 0

README

until

这是一golang常用函数库 并且我在一直维护,这个库引用了很多朋友开源库,我很感谢他们,稍后公布他们地址,当我整理的差不多的时候

本库剽窃如下大神代码: github.com/chanyipiaomiao/hltool 大帅哥一枚 https://github.com/goinggo/mapstructure 一个跨国友人

Documentation

Index

Constants

View Source
const (

	// RSAAlgorithmSign RSA签名算法
	RSAAlgorithmSign = crypto.SHA1
)

Variables

This section is empty.

Functions

func Authcode

func Authcode(s string, operation string, key string) string

Authcode encrypt/decrypt token

func Base64Encode

func Base64Encode(data []byte) string

简化Base64

func BinFileToStruct

func BinFileToStruct(filepath string, to interface{}) error

BinFileToStruct 二级制文件反序列化为结构体,结构体必须要和转换前的结构一致 filepath 二进制文件路径 to 结构体对象 结构必须和序列化前的一样

func BytesToFile

func BytesToFile(data []byte, filepath string) error

BytesToFile 字节数组写入到文件

func BytesToStruct

func BytesToStruct(data []byte, to interface{}) error

BytesToStruct []byte转换为结构体,必须事先知道结构体的结构,而且必须一样 data 转换后的字节数组 to 结构体对象 结构必须和序列化前的一样

func CheckToken

func CheckToken(token string, secretKey string) ([]interface{}, error)

CheckToken decrypt token

func CryptPassword

func CryptPassword(password, salt string) string

CryptPassword 加密密码

func CurrentDir

func CurrentDir() string

CurrentDir 获取当前路径

func CurrentUser

func CurrentUser() string

CurrentUser 获取当前SSH连接的用户

func Decode

func Decode(m interface{}, rawVal interface{}) error

Decode takes a map and uses reflection to convert it into the given Go native structure. val must be a pointer to a struct.

func DecodePath

func DecodePath(m map[string]interface{}, rawVal interface{}) error

DecodePath takes a map and uses reflection to convert it into the given Go native structure. Tags are used to specify the mapping between fields in the map and structure

func DecodeSlicePath

func DecodeSlicePath(ms []map[string]interface{}, rawSlice interface{}) error

DecodeSlicePath decodes a slice of maps against a slice of structures that contain specified tags

func EarthDistance

func EarthDistance(lat1, lng1, lat2, lng2 float64) float64

EarthDistance 计算两个经纬度之间的距离 单位为米 纬度1、经度1、纬度2、经度2

func FormatUnixTime

func FormatUnixTime(unixTime int64) string

FormatUnixTime 将时间戳格式化

func GenRandomString

func GenRandomString(length int, specialChar string) string

GenRandomString 生成随机字符串 length 生成长度 specialChar 是否生成特殊字符

func GenRangeInt

func GenRangeInt(length int, from int) []int

GenRangeInt 创建一个长度为length的slice 值为连续的整形,第一个数为from

func GenToken

func GenToken(userId int, extraStr string, secretKey string) string

GenToken 生成token字符串

func GetChinaWeekDay

func GetChinaWeekDay() int

GetChinaWeekDay 获取中国的星期几

func GetIP

func GetIP(conn *net.TCPConn) string

GetIP 读取客户端IP

func GetIntSliceFromFile

func GetIntSliceFromFile(file, splitString string) ([]int, error)

GetIntSliceFromFile 从文件中读取[]int结构 用\n作为行分隔符, "splitString"作为列分隔符

func GetMapMaxValue

func GetMapMaxValue(m map[int]int) (int, []int)

GetMapMaxValue 获取map[int]int中最大值, 并返回所有key的集合 value约定是大于0的

func GetMapMinValue

func GetMapMinValue(m map[int]int) (int, []int)

GetMapMinValue 获取map[int]int中最小值, 并返回所有key的集合 value约定是大于0的

func GetMapValues

func GetMapValues(m map[int]int) []int

GetMapValues 获取map[int]int结构的所有value 返回结果去重

func GetMicrotime

func GetMicrotime() string

GetMicrotime 获取微秒时间

func GetMillsTime

func GetMillsTime() int64

GetMillsTime 获取当前微秒时间

func GetNowTime

func GetNowTime() string

GetNowTime 获取当前时间

func GetRandString

func GetRandString(n int) string

GetRandString 生成n位随机数字字符串

func GetTime

func GetTime() int64

GetTime 获取当前时间戳

func GetTimestamp

func GetTimestamp() string

GetTimestamp 获取当前格式化时间

func GetYMD

func GetYMD() string

GetYMD 获取当前年月日

func InStringSlice

func InStringSlice(finder string, slice []string) bool

InStringSlice 判断某个string值是否在切片中

func IntInSlice

func IntInSlice(finder int, slice []int) bool

IntInSlice 判断某个int值是否在切片中

func InterfaceToJsonString

func InterfaceToJsonString(s interface{}) (string, error)

InterfaceToJsonString 将任意类型的数据,转成json格式的字符串

func IsExist

func IsExist(name string) bool

IsExist 文件或目录是否存在 return false 表示文件不存在

func IsNumber

func IsNumber(input string) bool

IsNumber 检查输入的字符串是否匹配数字

func IsSameSlice

func IsSameSlice(slice1, slice2 []int) bool

IsSameSlice 判断两个slice是否相等

func JSONBytesToFile

func JSONBytesToFile(data []byte, filepath string) error

JSONBytesToFile json []byte 写入文件

func JSONFileToBytes

func JSONFileToBytes(filepath string) ([]byte, error)

JSONFileToBytes 从json文件中转换为[]byte

func JsonEncode

func JsonEncode(m JsonMap) ([]byte, error)

JsonEncode 将JsonMap转成[]byte

func MapToSlice

func MapToSlice(m map[int]int) []int

MapToSlice 将map[int]count 转成 []int

func MarshalPKCS8PrivateKey

func MarshalPKCS8PrivateKey(key *rsa.PrivateKey) []byte

MarshalPKCS8PrivateKey 私钥解析

func Md5Sum

func Md5Sum(s string) string

Md5Sum 获取字符串的md5值

func MergeMap

func MergeMap(args ...map[int]int) map[int]int

MergeMap 合并两个map[int]int

func NewRSAFile

func NewRSAFile(pubKeyFilename, priKeyFilename string, keyLength int) error

NewRSAFile 生成密钥对文件 pubKeyFilename: 公钥文件名 priKeyFilename: 私钥文件名 kekeyLength: 密钥长度

func NewRSAString

func NewRSAString(keyLength int) (string, string, error)

NewRSAString 生成密钥对字符串 keyLength 密钥的长度

func PostData

func PostData(post_data interface{}, sinapay_url string) (result map[string]interface{}, err error)

func QueryStr

func QueryStr(query_balance_post interface{}, upost bool, slice []string) string

结构体拼接字符串

func RandIntn

func RandIntn(n int) int

RandIntn 获取一个 0 ~ n 之间的随机值

func ReadRSAKeyPair

func ReadRSAKeyPair(pubKeyFilename, priKeyFilename string) ([]byte, []byte, error)

ReadRSAKeyPair 读取RSA密钥对 pubKeyFilename: 公钥文件名称 priKeyFilename: 私钥文件名

func RecoverPanic

func RecoverPanic()

RecoverPanic 捕获panic错误

func SMapIsEmpty

func SMapIsEmpty(smap *sync.Map) bool

SMapIsEmpty 判断sync.Map是否为空

func SMapLen

func SMapLen(smap *sync.Map) int

SMapLen 获取sync.Map的元素个数

func ShuffleSliceInt

func ShuffleSliceInt(src []int) []int

ShuffleSliceInt 打乱一个切片

func SliceCopy

func SliceCopy(s []int) []int

SliceCopy 拷贝一个切片

func SliceDel

func SliceDel(slice []int, values ...int) []int

SliceDel 删除slice中的某些元素

func SliceDelString

func SliceDelString(slice []string, values ...string) []string

SliceDelString 删除slice中的某些元素

func SliceJoin

func SliceJoin(s []int, joinString string) string

SliceJoin 将一个slice拼接成一个字符串

func SliceMaxInt

func SliceMaxInt(s []int) int

SliceMaxInt 取int类型的最大值

func SliceToMap

func SliceToMap(slice []int) map[int]int

SliceToMap 将[]int 转化成map[int]count

func SliceUniqueInt

func SliceUniqueInt(s []int) []int

SliceUniqueInt 去重

func StructToBinFile

func StructToBinFile(structObj interface{}, filepath string) error

StructToBinFile 结构体序列化成二级制文件 structObj 结构体对象 filepath 文件路径

func StructToBytes

func StructToBytes(structObj interface{}) ([]byte, error)

StructToBytes 结构体转换为[]byte structObj 结构体对象

func UidString

func UidString() string

func Urlencode

func Urlencode(data map[string]interface{}, slice []string) string

func UserHome

func UserHome() (string, error)

UserHome 获取用户的家目录

func WriteRSAKeyPair

func WriteRSAKeyPair(publicKeyWriter, privateKeyWriter io.Writer, keyLength int) error

WriteRSAKeyPair 生成RSA密钥对

Types

type DecodeHookFunc

type DecodeHookFunc func(reflect.Kind, reflect.Kind, interface{}) (interface{}, error)

type Decoder

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

A Decoder takes a raw interface value and turns it into structured data, keeping track of rich error information along the way in case anything goes wrong. Unlike the basic top-level Decode method, you can more finely control how the Decoder behaves using the DecoderConfig structure. The top-level Decode method is just a convenience that sets up the most basic Decoder.

func NewDecoder

func NewDecoder(config *DecoderConfig) (*Decoder, error)

NewDecoder returns a new decoder for the given configuration. Once a decoder has been returned, the same configuration must not be used again.

func NewPathDecoder

func NewPathDecoder(config *DecoderConfig) (*Decoder, error)

NewPathDecoder returns a new decoder for the given configuration. This is used to decode path specific structures

func (*Decoder) Decode

func (d *Decoder) Decode(raw interface{}) error

Decode decodes the given raw interface to the target pointer specified by the configuration.

func (*Decoder) DecodePath

func (d *Decoder) DecodePath(m map[string]interface{}, rawVal interface{}) (bool, error)

DecodePath decodes the raw interface against the map based on the specified tags

type DecoderConfig

type DecoderConfig struct {
	// DecodeHook, if set, will be called before any decoding and any
	// type conversion (if WeaklyTypedInput is on). This lets you modify
	// the values before they're set down onto the resulting struct.
	//
	// If an error is returned, the entire decode will fail with that
	// error.
	DecodeHook DecodeHookFunc

	// If ErrorUnused is true, then it is an error for there to exist
	// keys in the original map that were unused in the decoding process
	// (extra keys).
	ErrorUnused bool

	// If WeaklyTypedInput is true, the decoder will make the following
	// "weak" conversions:
	//
	//   - bools to string (true = "1", false = "0")
	//   - numbers to string (base 10)
	//   - bools to int/uint (true = 1, false = 0)
	//   - strings to int/uint (base implied by prefix)
	//   - int to bool (true if value != 0)
	//   - string to bool (accepts: 1, t, T, TRUE, true, True, 0, f, F,
	//     FALSE, false, False. Anything else is an error)
	//   - empty array = empty map and vice versa
	//
	WeaklyTypedInput bool

	// Metadata is the struct that will contain extra metadata about
	// the decoding. If this is nil, then no metadata will be tracked.
	Metadata *Metadata

	// Result is a pointer to the struct that will contain the decoded
	// value.
	Result interface{}

	// The tag name that mapstructure reads for field names. This
	// defaults to "mapstructure"
	TagName string
}

DecoderConfig is the configuration that is used to create a new decoder and allows customization of various aspects of decoding.

type Error

type Error struct {
	Errors []string
}

Error implements the error interface and can represents multiple errors that occur in the course of a single decode.

func (*Error) Error

func (e *Error) Error() string

type GoAES

type GoAES struct {
	Key []byte
}

GoAES 加密

func NewGoAES

func NewGoAES(key []byte) *GoAES

NewGoAES 返回GoAES

func (*GoAES) Decrypt

func (a *GoAES) Decrypt(crypted []byte) ([]byte, error)

Decrypt 解密数据

func (*GoAES) Encrypt

func (a *GoAES) Encrypt(origData []byte) ([]byte, error)

Encrypt 加密数据

type GoRSA

type GoRSA struct {
	PublicKey  *rsa.PublicKey
	PrivateKey *rsa.PrivateKey
}

GoRSA RSA加密解密

func NewGoRSA

func NewGoRSA(pubKeyFilename, priKeyFilename string) (*GoRSA, error)

NewGoRSA 初始化 GoRSA对象

func (*GoRSA) PrivateDecrypt

func (r *GoRSA) PrivateDecrypt(encrypted []byte) ([]byte, error)

PrivateDecrypt 私钥解密

func (*GoRSA) PublicEncrypt

func (r *GoRSA) PublicEncrypt(data []byte) ([]byte, error)

PublicEncrypt 公钥加密

func (*GoRSA) Sign

func (r *GoRSA) Sign(data string) ([]byte, error)

Sign 数据进行签名

func (*GoRSA) Verify

func (r *GoRSA) Verify(data string, sign string) error

Verify 数据验证签名

type JsonMap

type JsonMap map[string]interface{}

JsonMap 存储任意数据的map

func JsonDecode

func JsonDecode(b []byte) (JsonMap, error)

JsonDecode 将[]byte转成JsonMap

func (JsonMap) JsonGetInt

func (m JsonMap) JsonGetInt(key string) (int, bool)

JsonGetInt 从JsonMap中解析出一个int值

func (JsonMap) JsonGetJsonMap

func (this JsonMap) JsonGetJsonMap(key string) JsonMap

JsonGetJsonMap 从JsonMap中解析出一个JsonMap值

func (JsonMap) JsonGetString

func (m JsonMap) JsonGetString(key string) (string, bool)

JsonGetString 从JsonMap中解析出一个string值

func (JsonMap) JsonGetUint16

func (m JsonMap) JsonGetUint16(key string) (uint16, bool)

JsonGetUint16 从JsonMap中解析出一个ushort值

type Metadata

type Metadata struct {
	// Keys are the keys of the structure which were successfully decoded
	Keys []string

	// Unused is a slice of keys that were found in the raw value but
	// weren't decoded since there was no matching field in the result interface
	Unused []string
}

Metadata contains information about decoding a structure that is tedious or difficult to get otherwise.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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