util

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

提供一些实用函数

Index

Constants

This section is empty.

Variables

View Source
var BeijingLocation = time.FixedZone("Asia/Shanghai", 8*60*60)
View Source
var DefaultHttpClient *http.Client
View Source
var DefaultMediaHttpClient *http.Client

Functions

func AESDecryptData

func AESDecryptData(cipherText []byte, aesKey []byte, iv []byte) (rawData []byte, err error)

func AESDecryptMsg

func AESDecryptMsg(ciphertext []byte, aesKey []byte) (random, rawXMLMsg, appId []byte, err error)

ciphertext = AES_Encrypt[random(16B) + msg_len(4B) + rawXMLMsg + appId]

func AESEncryptMsg

func AESEncryptMsg(random, rawXMLMsg []byte, appId string, aesKey []byte) (ciphertext []byte)

ciphertext = AES_Encrypt[random(16B) + msg_len(4B) + rawXMLMsg + appId]

func BoolPtr

func BoolPtr(v bool) *bool

Bool is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func DecodeXMLToMap

func DecodeXMLToMap(r io.Reader) (m map[string]string, err error)

DecodeXMLToMap decodes xml reading from io.Reader and returns the first-level sub-node key-value set, if the first-level sub-node contains child nodes, skip it.

func EncodeXMLFromMap

func EncodeXMLFromMap(w io.Writer, m map[string]string, rootname string) (err error)

EncodeXMLFromMap encodes map[string]string to io.Writer with xml format.

NOTE: This function requires the rootname argument and the keys of m (type map[string]string) argument
are legitimate xml name string that does not contain the required escape character!

func Float32Ptr

func Float32Ptr(v float32) *float32

Float32 is a helper routine that allocates a new float32 value to store v and returns a pointer to it.

func Float64Ptr

func Float64Ptr(v float64) *float64

Float64 is a helper routine that allocates a new float64 value to store v and returns a pointer to it.

func GetStringsBuilder

func GetStringsBuilder() *strings.Builder

func GetUrlValues

func GetUrlValues() url.Values

func HttpResponseWriter

func HttpResponseWriter(w io.Writer) http.ResponseWriter

将 io.Writer 从语义上实现 http.ResponseWriter.

func Int32Ptr

func Int32Ptr(v int32) *int32

Int32 is a helper routine that allocates a new int32 value to store v and returns a pointer to it.

func Int64Ptr

func Int64Ptr(v int64) *int64

Int64 is a helper routine that allocates a new int64 value to store v and returns a pointer to it.

func IntPtr

func IntPtr(v int) *int

Int is a helper routine that allocates a new int value to store v and returns a pointer to it.

func MsgSign

func MsgSign(token, timestamp, nonce, encryptedMsg string) (signature string)

MsgSign 微信公众号/企业号 消息体签名.

func NonceStr

func NonceStr() string

func PutStringsBuilder

func PutStringsBuilder(b *strings.Builder)

func PutUrlValues

func PutUrlValues(values url.Values)

func SecureCompare

func SecureCompare(given, actual []byte) bool

func SecureCompareString

func SecureCompareString(given, actual string) bool

func Sign

func Sign(token, timestamp, nonce string) (signature string)

Sign 微信公众号 url 签名.

func StringPtr

func StringPtr(v string) *string

String is a helper routine that allocates a new string value to store v and returns a pointer to it.

func StringsJoin

func StringsJoin(strs ...string) string

func ToLower

func ToLower(s string) string

ToLower 返回字符串对应的小写版本.

如果确定 s 是[a-zA-Z0-9_-] 的组合, 那么可以用这个函数, 否则请用 strings.ToLower!

func Uint32Ptr

func Uint32Ptr(v uint32) *uint32

Uint32 is a helper routine that allocates a new uint32 value to store v and returns a pointer to it.

func Uint64Ptr

func Uint64Ptr(v uint64) *uint64

Uint64 is a helper routine that allocates a new uint64 value to store v and returns a pointer to it.

func WXVersion

func WXVersion(userAgent string) (x, y, z, w int, err error)

获取微信客户端的版本.

userAgent: 微信内置浏览器的 User-Agent;
x, y, z, w:   如果微信版本为 5.3.1.2 则有 x==5, y==3, z==1, w==2
err:       错误信息

Types

type Int64

type Int64 int64

Int64 support string quoted number in json

func (Int64) Int64

func (i64 Int64) Int64() int64

func (*Int64) UnmarshalJSON

func (i64 *Int64) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON implement json Unmarshal interface

type MoneyFloat

type MoneyFloat float64

MoneyFloat support string quoted number in json

func (MoneyFloat) Float64

func (f64 MoneyFloat) Float64() float64

func (*MoneyFloat) UnmarshalJSON

func (f64 *MoneyFloat) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON implement json Unmarshal interface

type Uint64

type Uint64 uint64

Uint64 support string quoted number in json

func (Uint64) Uint64

func (u64 Uint64) Uint64() uint64

func (*Uint64) UnmarshalJSON

func (u64 *Uint64) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON implement json Unmarshal interface

Jump to

Keyboard shortcuts

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