util

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2018 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const CustomHeader = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>`

CustomHeader xml header

View Source
const FieldLimit = "limit"

FieldLimit ...

View Source
const FieldSign = "sign"

FieldSign ...

View Source
const FieldSignType = "sign_type"

FieldSignType ...

View Source
const HMACSHA256 = "HMAC-SHA256"

HMACSHA256 定义:HMAC-SHA256

View Source
const MD5 = "MD5"

MD5 定义:MD5

Variables

View Source
var (
	ErrorSignType  = errors.New("sign type error")
	ErrorParameter = errors.New("JsonApiParameters() check error")
	ErrorToken     = errors.New("EditAddressParameters() token is nil")
)

error types

View Source
var ErrNilMap = errors.New("nil map")

ErrNilMap ...

View Source
var (
	RandomString = map[RandomKind]string{
		RandomNum:      "0123456789",
		RandomLower:    "abcdefghijklmnopqrstuvwxyz",
		RandomUpper:    "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
		RandomLowerNum: "0123456789abcdefghijklmnopqrstuvwxyz",
		RandomUpperNum: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
		RandomAll:      "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
	}
)

RandomString defines

Functions

func CurrentTimeStamp

func CurrentTimeStamp() int64

CurrentTimeStamp get current time with unix

func CurrentTimeStampMS

func CurrentTimeStampMS() int64

CurrentTimeStampMS get current time with millisecond

func CurrentTimeStampNS

func CurrentTimeStampNS() int64

CurrentTimeStampNS get current time with nanoseconds

func CurrentTimeStampString

func CurrentTimeStampString() string

CurrentTimeStampString get current time to string

func GenerateNonceStr

func GenerateNonceStr() string

GenerateNonceStr GenerateNonceStr

func GenerateRandomString

func GenerateRandomString(size int, kind ...RandomKind) string

GenerateRandomString 随机字符串

func GenerateRandomString2

func GenerateRandomString2(size int, kind int) []byte

GenerateRandomString2 随机字符串

func GenerateSignature added in v1.1.2

func GenerateSignature(p Map, key string, fn SignFunc) string

GenerateSignature make sign from map data

func GenerateSignatureWithIgnore added in v1.1.2

func GenerateSignatureWithIgnore(p Map, key string, ignore []string) string

GenerateSignatureWithIgnore ...

func GenerateUUID

func GenerateUUID() string

GenerateUUID GenerateUUID

func HmacSha256 added in v1.1.4

func HmacSha256(data []byte, key string) string

func In

func In(source []string, v string) bool

In check v is in source

func InterfaceToMap added in v1.1.4

func InterfaceToMap(v interface{}, m *Map) error

func MakeSignHMACSHA256 added in v1.1.2

func MakeSignHMACSHA256(data, key string) string

MakeSignHMACSHA256 make sign with hmac-sha256

func MakeSignMD5 added in v1.1.2

func MakeSignMD5(data, key string) string

MakeSignMD5 make sign with md5

func MapToString

func MapToString(data Map, ignore []string) string

MapToString MapToString

func MapToXML

func MapToXML(m Map) ([]byte, error)

MapToXML Convert MAP to XML

func ParseInt

func ParseInt(v interface{}) (int64, bool)

ParseInt parse interface to int64

func ParseNumber

func ParseNumber(v interface{}) (float64, bool)

ParseNumber parse interface to number

func ParseString added in v1.0.1

func ParseString(v interface{}) (string, bool)

ParseString parse interface to string

func SHA1

func SHA1(s string) string

SHA1 transfer string to sha1

func Time

func Time(t ...time.Time) string

Time get time string

func ToURLParams

func ToURLParams(data Map, ignore []string) string

ToURLParams map to url params

func ValidateSign added in v1.1.2

func ValidateSign(maps Map, key string) bool

ValidateSign check the sign validate

Types

type CDATA

type CDATA struct {
	XMLName xml.Name
	Value   string `xml:",cdata"`
}

CDATA xml cdata defines

type Map

type Map map[string]interface{}

Map Map

func JSONToMap

func JSONToMap(content []byte) Map

JSONToMap Convert JSON to MAP

func MapNilMake

func MapNilMake(m Map) Map

MapNilMake if m is nil result a nil map

func MapToMap added in v1.0.1

func MapToMap(p map[string]interface{}) Map

MapToMap transfer to map[string]interface{} to Map

func MapsToMap added in v1.0.1

func MapsToMap(p Map, m []Map) Map

MapsToMap ...

func XMLToMap

func XMLToMap(contentXML []byte) Map

XMLToMap Convert XML to MAP

func (Map) Append added in v1.1.1

func (m Map) Append(p Map) Map

Append ...

func (Map) Check added in v1.0.1

func (m Map) Check(s ...string) int

Check check all input keys return -1 if all is exist return index when not found

func (Map) Clone

func (m Map) Clone() Map

Clone copy a map

func (Map) Delete

func (m Map) Delete(key string) bool

Delete delete if exist

func (Map) DeletePath added in v1.0.1

func (m Map) DeletePath(keys []string) bool

DeletePath ...

func (Map) Expect added in v1.0.1

func (m Map) Expect(keys []string) Map

Expect get map expect keys

func (Map) Get

func (m Map) Get(key string) interface{}

Get get interface from map with out default

func (Map) GetArray added in v1.1.1

func (m Map) GetArray(s string) []interface{}

GetArray ...

func (Map) GetArrayD added in v1.1.1

func (m Map) GetArrayD(s string, d []interface{}) []interface{}

GetArrayD ...

func (Map) GetBool

func (m Map) GetBool(s string) bool

GetBool get bool from map with out default

func (Map) GetBoolD

func (m Map) GetBoolD(s string, b bool) bool

GetBoolD get bool from map with default

func (Map) GetBytes

func (m Map) GetBytes(s string) []byte

GetBytes get bytes from map with default

func (Map) GetD

func (m Map) GetD(s string, d interface{}) interface{}

GetD get interface from map with default

func (Map) GetInt64

func (m Map) GetInt64(s string) (int64, bool)

GetInt64 get int64 from map with out default

func (Map) GetInt64D added in v1.0.1

func (m Map) GetInt64D(s string, d int64) int64

GetInt64D get int64 from map with default

func (Map) GetMap

func (m Map) GetMap(s string) Map

GetMap get map from map with out default

func (Map) GetMapArray added in v1.0.1

func (m Map) GetMapArray(s string) []Map

GetMapArray get map from map with out default

func (Map) GetMapArrayD added in v1.0.1

func (m Map) GetMapArrayD(s string, d []Map) []Map

GetMapArrayD get map from map with default

func (Map) GetMapD

func (m Map) GetMapD(s string, d Map) Map

GetMapD get map from map with default

func (Map) GetNumber

func (m Map) GetNumber(s string) (float64, bool)

GetNumber get float64 from map with out default

func (Map) GetNumberD

func (m Map) GetNumberD(s string, d float64) float64

GetNumberD get float64 from map with default

func (Map) GetPath added in v1.0.1

func (m Map) GetPath(keys []string) interface{}

GetPath returns the element in the tree indicated by 'keys'. If keys is of length zero, the current tree is returned.

func (Map) GetString

func (m Map) GetString(s string) string

GetString get string from map with out default

func (Map) GetStringD

func (m Map) GetStringD(s string, d string) string

GetStringD get string from map with default

func (Map) Has

func (m Map) Has(key string) bool

Has check if key exist

func (Map) HasPath added in v1.0.1

func (m Map) HasPath(keys []string) bool

HasPath returns true if the given path of keys exists, false otherwise.

func (Map) Join

func (m Map) Join(s Map) Map

Join insert map s to m with out replace

func (Map) Map added in v1.0.1

func (m Map) Map() map[string]interface{}

Map trans Map to map[string]interface

func (Map) MarshalXML added in v1.1.1

func (m Map) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML ...

func (Map) Only

func (m Map) Only(keys []string) Map

Only get map with keys

func (Map) ParseJSON

func (m Map) ParseJSON(b []byte) Map

ParseJSON parse JSON bytes to map

func (Map) ParseXML

func (m Map) ParseXML(b []byte)

ParseXML parse XML bytes to map

func (Map) Range added in v1.0.1

func (m Map) Range(f func(key string, value interface{}) bool)

Range range all maps

func (Map) ReplaceJoin

func (m Map) ReplaceJoin(s Map) Map

ReplaceJoin insert map s to m with replace

func (Map) Set

func (m Map) Set(key string, v interface{}) Map

Set set interface

func (Map) SetGet added in v1.0.1

func (m Map) SetGet(s string, v Map) Map

SetGet set value from map if key is exist

func (Map) SetHas added in v1.0.1

func (m Map) SetHas(s string, v interface{}) Map

SetHas set interface if key is exist

func (Map) SetNil added in v1.0.1

func (m Map) SetNil(s string, v interface{}) Map

SetNil set interface if key is not exist

func (Map) SetPath added in v1.0.1

func (m Map) SetPath(keys []string, v interface{}) Map

SetPath is the same as SetPath, but allows you to provide comment information to the key, that will be reused by Marshal().

func (Map) SortKeys

func (m Map) SortKeys() []string

SortKeys 排列key

func (Map) String

func (m Map) String() string

String transfer map to JSON string

func (Map) ToJSON

func (m Map) ToJSON() []byte

ToJSON transfer map to JSON

func (Map) ToXML

func (m Map) ToXML() []byte

ToXML transfer map to XML

func (Map) URLEncode

func (m Map) URLEncode() string

URLEncode transfer map to url encode

func (Map) URLToSHA1

func (m Map) URLToSHA1() string

URLToSHA1 make sha1 from map

func (Map) UnmarshalXML added in v1.1.1

func (m Map) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML ...

type RandomKind

type RandomKind int

RandomKind RandomKind

const (
	RandomNum      RandomKind = iota // 纯数字
	RandomLower                      // 小写字母
	RandomUpper                      // 大写字母
	RandomLowerNum                   // 数字、小写字母
	RandomUpperNum                   // 数字、大写字母
	RandomAll                        // 数字、大小写字母
)

random kinds

type SignFunc added in v1.1.2

type SignFunc func(data, key string) string

SignFunc sign函数定义

type String

type String string

String String

func ToString

func ToString(s string) String

ToString ToString

func (String) String

func (s String) String() string

String String

type StringAble

type StringAble interface {
	String() string
}

StringAble StringAble

Jump to

Keyboard shortcuts

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