util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const NULL = ""

Variables

View Source
var TimeOut time.Duration = 60 * time.Second

TimeOut 全局请求超时设置,默认1分钟

Functions

func AesDecrypt

func AesDecrypt(src, key []byte) (dst []byte, err error)

AesDecrypt AES-CBC解密,PKCS#7,传入密文和密钥,[]byte

func AesEncrypt

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

AesEncrypt AES-CBC加密+PKCS#7打包,传入明文和密钥

func ConvertToString

func ConvertToString(v interface{}) (str string)

func GetBody

func GetBody(uri string) ([]byte, error)

GetBody 发送GET请求,返回body字节

func GetFile

func GetFile(filename, uri string) error

GetFile 下载文件

func GetJson

func GetJson(uri string, v interface{}) error

GetJson 发送GET请求解析json

func GetRandomString

func GetRandomString(l int) string

GetRandomString 获得随机字符串

func GetXml

func GetXml(uri string, v interface{}) error

GetXml 发送GET请求并解析xml

func Min

func Min(first int, args ...int) int

Min golang min int

func PKCS7Pad

func PKCS7Pad(msg []byte, blockSize int) []byte

PKCS7Pad PKCS#7打包

func PKCS7UnPad

func PKCS7UnPad(msg []byte) []byte

PKCS7UnPad PKSC#7解包

func PostFile

func PostFile(fieldname, filename, uri string) ([]byte, error)

PostFile 上传文件

func PostJson

func PostJson(uri string, obj interface{}) ([]byte, error)

PostJson 发送Json格式的POST请求

func PostJsonPtr

func PostJsonPtr(uri string, obj interface{}, result interface{}, contentType ...string) (err error)

PostJsonPtr 发送Json格式的POST请求并解析结果到result指针

func PostMultipartForm

func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte, err error)

PostMultipartForm 上传文件或其他表单数据

func PostXmlPtr

func PostXmlPtr(uri string, obj interface{}, result interface{}) (err error)

PostXmlPtr 发送Xml格式的POST请求并解析结果到result指针

func SetHTTPClientFactory

func SetHTTPClientFactory(f func() *http.Client)

func SetTimeOut

func SetTimeOut(d time.Duration)

SetTimeOut 设置全局请求超时

func SortMd5

func SortMd5(s ...string) string

SortMd5 排序并md5,主要用于计算sign

func SortSha1

func SortSha1(s ...string) string

SortSha1 排序并sha1,主要用于计算signature

func Substr

func Substr(str string, start int, end int) string

Substr 截取字符串 start 起点下标 end 终点下标(不包括)

Types

type BodyMap

type BodyMap map[string]interface{}

func (BodyMap) CheckEmptyError

func (bm BodyMap) CheckEmptyError(keys ...string) error

func (BodyMap) EncodeAliPaySignParams

func (bm BodyMap) EncodeAliPaySignParams() string

("bar=baz&foo=quux") sorted by key.

func (BodyMap) EncodeGetParams

func (bm BodyMap) EncodeGetParams() string

("bar=baz&foo=quux")

func (BodyMap) EncodeWeChatSignParams

func (bm BodyMap) EncodeWeChatSignParams(apiKey string) string

("bar=baz&foo=quux") sorted by key.

func (BodyMap) Get

func (bm BodyMap) Get(key string) string

获取参数,同 GetString()

func (BodyMap) GetInterface

func (bm BodyMap) GetInterface(key string) interface{}

获取原始参数

func (BodyMap) GetString

func (bm BodyMap) GetString(key string) string

获取参数转换string

func (BodyMap) JsonBody

func (bm BodyMap) JsonBody() (jb string)

func (BodyMap) MarshalXML

func (bm BodyMap) MarshalXML(e *xml.Encoder, start xml.StartElement) (err error)

func (BodyMap) Remove

func (bm BodyMap) Remove(key string)

删除参数

func (BodyMap) Reset

func (bm BodyMap) Reset()

置空BodyMap

func (BodyMap) Set

func (bm BodyMap) Set(key string, value interface{}) BodyMap

设置参数

func (BodyMap) SetBodyMap

func (bm BodyMap) SetBodyMap(key string, value func(bm BodyMap)) BodyMap

func (BodyMap) SetFormFile

func (bm BodyMap) SetFormFile(fieldName string, filePath string) (err error)

设置 FormFile

func (*BodyMap) UnmarshalXML

func (bm *BodyMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error)

type MultipartFormField

type MultipartFormField struct {
	IsFile    bool
	Fieldname string
	Value     []byte
	Filename  string
}

MultipartFormField 文件或其他表单数据

Jump to

Keyboard shortcuts

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