tools

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const LetterArray = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
View Source
const LetterArrayCode = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"
View Source
const LetterArrayCodeLen = len(LetterArrayCode)
View Source
const LetterArrayLen = len(LetterArray)

Variables

View Source
var GRand = mrand.New(mrand.NewSource(time.Now().Unix()))
View Source
var OneDay, _ = time.ParseDuration("24h")

Functions

func AddDateByDayNum

func AddDateByDayNum(input *time.Time, dayNum int)

func Base64Decode

func Base64Decode(input string) string

func Base64Encode

func Base64Encode(input string) string

func CalcDayNum

func CalcDayNum(start *time.Time, end *time.Time) int

func Capitalize

func Capitalize(str string) string

func DateFromTime

func DateFromTime(input *time.Time) time.Time

func EndDayOfTheMonth

func EndDayOfTheMonth(in time.Time) time.Time

func GenRandomCodeStr

func GenRandomCodeStr(length int) string

func GenRandomStr

func GenRandomStr(length int) string

func Int64ToStr

func Int64ToStr(i int64) string

func LoadFile

func LoadFile(fileFullPath string) []byte

func PKCS7UnPadding

func PKCS7UnPadding(plantText []byte) ([]byte, error)

PKCS7UnPadding return unpadding []Byte plantText

func ParseZoneTime

func ParseZoneTime(input string) (time.Time, error)

func RandStr

func RandStr(length int) string

gen random string. 问题:数字部分过多

func StrToInt64

func StrToInt64(str string) (int64, error)

func VerifyCallback

func VerifyCallback(w http.ResponseWriter, r *http.Request) bool

客户端直传后,OSS的回调函数中调用该函数进行参数验证。这里都把返回值写入了http.ResponseWriter中

Types

type CallbackParam

type CallbackParam struct {
	CallbackUrl      string `json:"callbackUrl"`
	CallbackBody     string `json:"callbackBody"`
	CallbackBodyType string `json:"callbackBodyType"`
}

type ConfigStruct

type ConfigStruct struct {
	Expiration string     `json:"expiration"`
	Conditions [][]string `json:"conditions"`
}

type DataBox

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

func NewDataBox

func NewDataBox(data interface{}) *DataBox

功能:生成NewDataBox对象,以便向data(必须是slice)中的成员(slice中的成员)添加指定数据,数据由FetchObjsByKeysRetMapFunc或者 FetchObjsByKeysRetSliceFunc返回slice中的对象和map中的value可以是结构或者是结构的指针 keyFieldName指明后续获取数据的key,后续会收集所有的key,传到FetchObjs...函数,以便集中化获取数据,提升效率 通过SaveToField函数指明的fieldname,得到数据填充的位置 其它特点: 1. 可以回填对象或者对象Slice 2. 可以多重填充 3. 被填充对象为指针,填充对象为结构对象 这种情况会导致异常

func (*DataBox) JoinByMap

func (d *DataBox) JoinByMap(f FetchObjsByKeysRetMapFunc) *DataBox

func (*DataBox) KeyField

func (d *DataBox) KeyField(keyFieldName string) *DataBox

func (*DataBox) SaveToField

func (d *DataBox) SaveToField(fieldName string) error

type EscapeError

type EscapeError string

func (EscapeError) Error

func (e EscapeError) Error() string

type FetchObjsByKeysRetMapFunc

type FetchObjsByKeysRetMapFunc func(keyList interface{}) (key2ObjsMap interface{}) // map[key][]obj  or  map[key]obj  or map[key][]*obj  or  map[key]*obj

用户需要实现的函数:通过key列表来获取对象,用于JoinByMap key列表时data里面通过keyfield抽取的key列表 第一个返回的map的key为传入的key;map里面的value可以是查到的单个对象,也可以是一个可以对应的对象slice 与FetchObjsByKeysRetSliceFunc相比,性能更高,且子结构可以不带父对象的ID,缺点是需要多写点代码

type InvalidHostError

type InvalidHostError string

func (InvalidHostError) Error

func (e InvalidHostError) Error() string

type OssBucket

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

func InitOssBucket

func InitOssBucket(endPoint, accessKeyID, accessKeySecret, bucketName string, clientCacheTime int, callbackUrl, uploadDir string, tokenExpireTime int64) (*OssBucket, error)

endPoint, accessKeyID, accessKeySecret, bucketName string, clientCacheTime 为基础配置 callbackUrl uploadDir tokenExpireTime为客户端上传时的配置,callbackUrl为上传到oss的回调地址,uploadDir为上传的目录,tokenExpireTime为临时token的过期时间

func (*OssBucket) DeleteOssRes

func (bucket *OssBucket) DeleteOssRes(resourcePath string) bool

func (*OssBucket) GetPolicyToken

func (bucket *OssBucket) GetPolicyToken(tokenExpireTime int64) string

获取客户端直传签名 客户端直传文档:https://help.aliyun.com/document_detail/31925.html, go demo:https://help.aliyun.com/document_detail/91818.html?spm=a2c4g.11186623.2.18.6ff36e28eGmN06#concept-mhj-zzt-2fb

func (*OssBucket) SetOption

func (bucket *OssBucket) SetOption(resourcePath string, option *OssOption) bool

func (*OssBucket) UploadToOss

func (bucket *OssBucket) UploadToOss(resourcePath string, contentType string, reader io.Reader) bool

服务器端直传

type OssOption

type OssOption struct {
	ContentType string
	ClientCache string /*max-age=300*/
	Origin      string
}

type PolicyToken

type PolicyToken struct {
	AccessKeyId string `json:"accessid"`
	Host        string `json:"host"`
	Expire      int64  `json:"expire"`
	Signature   string `json:"signature"`
	Policy      string `json:"policy"`
	Directory   string `json:"dir"`
	Callback    string `json:"callback"`
}

type WxBizDataCrypt

type WxBizDataCrypt struct {
	AppID      string
	SessionKey string
}

WxBizDataCrypt represents an active WxBizDataCrypt object

func (*WxBizDataCrypt) Decrypt

func (wxCrypt *WxBizDataCrypt) Decrypt(encryptedData string, iv string, isJSON bool) (interface{}, error)

Decrypt Weixin APP's AES Data If isJSON is true, Decrypt return JSON type. If isJSON is false, Decrypt return map type.

Jump to

Keyboard shortcuts

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