Documentation ¶
Index ¶
- Constants
- func Authcode(s string, operation string, key string) string
- func Base64Encode(data []byte) string
- func BinFileToStruct(filepath string, to interface{}) error
- func BytesToFile(data []byte, filepath string) error
- func BytesToStruct(data []byte, to interface{}) error
- func CheckToken(token string, secretKey string) ([]interface{}, error)
- func CryptPassword(password, salt string) string
- func CurrentDir() string
- func CurrentUser() string
- func Decode(m interface{}, rawVal interface{}) error
- func DecodePath(m map[string]interface{}, rawVal interface{}) error
- func DecodeSlicePath(ms []map[string]interface{}, rawSlice interface{}) error
- func EarthDistance(lat1, lng1, lat2, lng2 float64) float64
- func FormatUnixTime(unixTime int64) string
- func GenRandomString(length int, specialChar string) string
- func GenRangeInt(length int, from int) []int
- func GenToken(userId int, extraStr string, secretKey string) string
- func GetChinaWeekDay() int
- func GetIP(conn *net.TCPConn) string
- func GetIntSliceFromFile(file, splitString string) ([]int, error)
- func GetMapMaxValue(m map[int]int) (int, []int)
- func GetMapMinValue(m map[int]int) (int, []int)
- func GetMapValues(m map[int]int) []int
- func GetMicrotime() string
- func GetMillsTime() int64
- func GetNowTime() string
- func GetRandString(n int) string
- func GetTime() int64
- func GetTimestamp() string
- func GetYMD() string
- func InStringSlice(finder string, slice []string) bool
- func IntInSlice(finder int, slice []int) bool
- func InterfaceToJsonString(s interface{}) (string, error)
- func IsExist(name string) bool
- func IsNumber(input string) bool
- func IsSameSlice(slice1, slice2 []int) bool
- func JSONBytesToFile(data []byte, filepath string) error
- func JSONFileToBytes(filepath string) ([]byte, error)
- func JsonEncode(m JsonMap) ([]byte, error)
- func MapToSlice(m map[int]int) []int
- func MarshalPKCS8PrivateKey(key *rsa.PrivateKey) []byte
- func Md5Sum(s string) string
- func MergeMap(args ...map[int]int) map[int]int
- func NewRSAFile(pubKeyFilename, priKeyFilename string, keyLength int) error
- func NewRSAString(keyLength int) (string, string, error)
- func PostData(post_data interface{}, sinapay_url string) (result map[string]interface{}, err error)
- func QueryStr(query_balance_post interface{}, upost bool, slice []string) string
- func RandIntn(n int) int
- func ReadRSAKeyPair(pubKeyFilename, priKeyFilename string) ([]byte, []byte, error)
- func RecoverPanic()
- func SMapIsEmpty(smap *sync.Map) bool
- func SMapLen(smap *sync.Map) int
- func ShuffleSliceInt(src []int) []int
- func SliceCopy(s []int) []int
- func SliceDel(slice []int, values ...int) []int
- func SliceDelString(slice []string, values ...string) []string
- func SliceJoin(s []int, joinString string) string
- func SliceMaxInt(s []int) int
- func SliceToMap(slice []int) map[int]int
- func SliceUniqueInt(s []int) []int
- func StructToBinFile(structObj interface{}, filepath string) error
- func StructToBytes(structObj interface{}) ([]byte, error)
- func UidString() string
- func Urlencode(data map[string]interface{}, slice []string) string
- func UserHome() (string, error)
- func WriteRSAKeyPair(publicKeyWriter, privateKeyWriter io.Writer, keyLength int) error
- type DecodeHookFunc
- type Decoder
- type DecoderConfig
- type Error
- type GoAES
- type GoRSA
- type JsonMap
- type Metadata
Constants ¶
const ( // RSAAlgorithmSign RSA签名算法 RSAAlgorithmSign = crypto.SHA1 )
Variables ¶
This section is empty.
Functions ¶
func BinFileToStruct ¶
BinFileToStruct 二级制文件反序列化为结构体,结构体必须要和转换前的结构一致 filepath 二进制文件路径 to 结构体对象 结构必须和序列化前的一样
func BytesToStruct ¶
BytesToStruct []byte转换为结构体,必须事先知道结构体的结构,而且必须一样 data 转换后的字节数组 to 结构体对象 结构必须和序列化前的一样
func CheckToken ¶
CheckToken decrypt token
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 ¶
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 ¶
DecodeSlicePath decodes a slice of maps against a slice of structures that contain specified tags
func EarthDistance ¶
EarthDistance 计算两个经纬度之间的距离 单位为米 纬度1、经度1、纬度2、经度2
func GenRandomString ¶
GenRandomString 生成随机字符串 length 生成长度 specialChar 是否生成特殊字符
func GenRangeInt ¶
GenRangeInt 创建一个长度为length的slice 值为连续的整形,第一个数为from
func GetIntSliceFromFile ¶
GetIntSliceFromFile 从文件中读取[]int结构 用\n作为行分隔符, "splitString"作为列分隔符
func GetMapMaxValue ¶
GetMapMaxValue 获取map[int]int中最大值, 并返回所有key的集合 value约定是大于0的
func GetMapMinValue ¶
GetMapMinValue 获取map[int]int中最小值, 并返回所有key的集合 value约定是大于0的
func GetMapValues ¶
GetMapValues 获取map[int]int结构的所有value 返回结果去重
func InStringSlice ¶
InStringSlice 判断某个string值是否在切片中
func InterfaceToJsonString ¶
InterfaceToJsonString 将任意类型的数据,转成json格式的字符串
func JSONBytesToFile ¶
JSONBytesToFile json []byte 写入文件
func JSONFileToBytes ¶
JSONFileToBytes 从json文件中转换为[]byte
func MarshalPKCS8PrivateKey ¶
func MarshalPKCS8PrivateKey(key *rsa.PrivateKey) []byte
MarshalPKCS8PrivateKey 私钥解析
func NewRSAFile ¶
NewRSAFile 生成密钥对文件 pubKeyFilename: 公钥文件名 priKeyFilename: 私钥文件名 kekeyLength: 密钥长度
func NewRSAString ¶
NewRSAString 生成密钥对字符串 keyLength 密钥的长度
func ReadRSAKeyPair ¶
ReadRSAKeyPair 读取RSA密钥对 pubKeyFilename: 公钥文件名称 priKeyFilename: 私钥文件名
func SliceDelString ¶
SliceDelString 删除slice中的某些元素
func StructToBinFile ¶
StructToBinFile 结构体序列化成二级制文件 structObj 结构体对象 filepath 文件路径
func StructToBytes ¶
StructToBytes 结构体转换为[]byte structObj 结构体对象
Types ¶
type DecodeHookFunc ¶
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
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.
type GoRSA ¶
type GoRSA struct { PublicKey *rsa.PublicKey PrivateKey *rsa.PrivateKey }
GoRSA RSA加密解密
func (*GoRSA) PrivateDecrypt ¶
PrivateDecrypt 私钥解密
func (*GoRSA) PublicEncrypt ¶
PublicEncrypt 公钥加密
type JsonMap ¶
type JsonMap map[string]interface{}
JsonMap 存储任意数据的map
func (JsonMap) JsonGetInt ¶
JsonGetInt 从JsonMap中解析出一个int值
func (JsonMap) JsonGetJsonMap ¶
JsonGetJsonMap 从JsonMap中解析出一个JsonMap值
func (JsonMap) JsonGetString ¶
JsonGetString 从JsonMap中解析出一个string值
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.