ant

package module
v0.0.0-...-fa37774 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2017 License: MIT Imports: 33 Imported by: 0

README

ant

Build Status Go Report Card GoDoc

A util library for golang.

Install

$ go get -u github.com/txthinking/ant

Contributing

  • Please contribute your pull request on develop branch
  • Please contain test case

License

Licensed under The MIT License

Documentation

Index

Constants

View Source
const AES256KeyLength = 32

AES256KeyLength is the length of key for AES 256 crypt

Variables

View Source
var DefaultDial = &Dial{
	Timeout: 10 * time.Second,
}

Functions

func AESCBCDecrypt

func AESCBCDecrypt(c, k []byte) ([]byte, error)

AESCBCDecrypt decrypt c with given k k should be 128/256 bits, otherwise it will append empty data or cut until 256 bits First 16 bytes of cipher data is the IV.

func AESCBCEncrypt

func AESCBCEncrypt(s, k []byte) ([]byte, error)

AESCBCEncrypt encrypt s with given k k should be 128/256 bits, otherwise it will append empty data or cut until 256 bits First 16 bytes of cipher data is the IV.

func AESCFBDecrypt

func AESCFBDecrypt(c, k []byte) ([]byte, error)

AESDecrypt decrypt c with given k k should be 128/256 bits, otherwise it will append empty data or cut until 256 bits First 16 bytes of cipher data is the IV.

func AESCFBEncrypt

func AESCFBEncrypt(s, k []byte) ([]byte, error)

AESCFBEncrypt encrypt s with given k. k should be 128/256 bits, otherwise it will append empty data or cut until 256 bits. First 16 bytes of cipher data is the IV.

func AESGCMDecrypt

func AESGCMDecrypt(c, k, n []byte) ([]byte, error)

AESGCMDecrypt decrypt s use k and nonce

func AESGCMEncrypt

func AESGCMEncrypt(s, k, n []byte) ([]byte, error)

AESGCMEncrypt encrypt s use k and nonce

func AESMake256Key

func AESMake256Key(k []byte) []byte

AESMake256Key cut or append empty data on the key and make sure the key lenth equal 32

func CheckHmacSha256

func CheckHmacSha256(message, messageMAC, key []byte) (bool, error)

func Decimal2IP

func Decimal2IP(n int64) string

Decimal2IP transform a decimal IP to x.x.x.x format.

func Decimal2IP0

func Decimal2IP0(n int64) (ip string, err error)

Decimal2IP0 transform a decimal IP to x.x.x.x format. ref: https://zh.wikipedia.org/wiki/IPv4

func Decimal2IP1

func Decimal2IP1(n int64) string

Decimal2IP1 transform a decimal IP to x.x.x.x format.

func GBK2UTF8

func GBK2UTF8(s []byte) ([]byte, error)

GBK2UTF8 transform s from GBK to UTF8 format

func GetAddressFromURL

func GetAddressFromURL(s string) (string, error)

func HasPort

func HasPort(host string) bool

func HkdfSha1RandomSalt

func HkdfSha1RandomSalt(secret, info []byte, sl int) (key []byte, salt []byte, err error)

func HkdfSha1WithSalt

func HkdfSha1WithSalt(secret, salt, info []byte) (key []byte, err error)

func HkdfSha256RandomSalt

func HkdfSha256RandomSalt(secret, info []byte, sl int) (key []byte, salt []byte, err error)

func HkdfSha256WithSalt

func HkdfSha256WithSalt(secret, salt, info []byte) (key []byte, err error)

func HmacSha256

func HmacSha256(message, key []byte) ([]byte, error)

func IP2Decimal

func IP2Decimal(ipstr string) (int64, error)

IP2Decimal transform ip format like x.x.x.x to decimal.

func IP2Decimal0

func IP2Decimal0(ip string) (n int64, err error)

IP2Decimal0 transform ip format like x.x.x.x to decimal. ref: https://zh.wikipedia.org/wiki/IPv4

func IP2Decimal1

func IP2Decimal1(ipstr string) (int64, error)

IP2Decimal1 transform ip format like x.x.x.x to decimal.

func IsBankCard

func IsBankCard(n int64) (ok bool, err error)

IsBankCard determine whether it is bankcard number

func IsChineseID

func IsChineseID(s string) (ok bool, err error)

IsChineseID determine whether it is Chinese ID Card Number

func IsChineseWords

func IsChineseWords(words string) (ok bool, err error)

IsChineseWords determine whether it is Chinese words Notice: NOT ALL

func IsEmail

func IsEmail(email string) (ok bool, err error)

IsEmail determine whether it is email address

func Json

func Json(w http.ResponseWriter, v interface{})

func MD5

func MD5(s string) (r string)

MD5 encrypt s according to md5 algorithm

func Markdown

func Markdown(markdown []byte) (html []byte)

Markdown format input to html

func MultipartFormDataFromFile

func MultipartFormDataFromFile(params, files map[string][]string, boundary string) (ior io.Reader, err error)

MultipartFormDataFromFile generate multipart form data according to RFC 2388. files is the paths of your files

func MultipartFormDataFromReader

func MultipartFormDataFromReader(params map[string][]string, files map[string][]io.Reader, boundary string) (ior io.Reader, err error)

MultipartFormDataFromReader generate multipart form data according to RFC 2388.

func PKCS5Padding

func PKCS5Padding(c []byte, blockSize int) []byte

PKCS5Padding can append data of PKCS5 Common blockSize is aes.BlockSize

func PKCS5UnPadding

func PKCS5UnPadding(s []byte) ([]byte, error)

PKCS5UnPadding can unappend data of PKCS5

func Random

func Random(min, max int64) int64

Random used to get a random number between min and max

func RandomNumber

func RandomNumber() (i int64)

RandomNumber used to get a random number

func SHA1

func SHA1(s string) (r string)

SHA1 encrypt s according to sha1 algorithm

func SHA256

func SHA256(s []byte) ([]byte, error)

SHA256 encrypt s according to sha256 algorithm

func SHA256String

func SHA256String(s string) (r string)

SHA256 encrypt s according to sha256 algorithm

func ToString

func ToString(data interface{}) (string, error)

ToString convert data to string, data must be one of map[string]string, map[string]interface{}, string, []string, struct

func UTF82GBK

func UTF82GBK(s []byte) ([]byte, error)

UTF82GBK transform s from UTF8 to GBK format

Types

type CIDRInfo

type CIDRInfo struct {
	First   string
	Last    string
	Block   int64
	Network string
	Count   int64
}

CIDRInfo is the struct of CIDR

func CIDR

func CIDR(cidr string) (c *CIDRInfo, err error)

CIDR return *CIDRInfo from like this x.x.x.x/x ref: http://goo.gl/AEUIi8

type CryptKV

type CryptKV struct {
	AESKey    []byte
	LifeCycle int
}

CryptKV can be used to crypt value by key and give it a lifecycle (s). Can be used in cookies

func (*CryptKV) Decrypt

func (kv *CryptKV) Decrypt(c string, k string) (string, error)

Decrypt key, value

func (*CryptKV) DecryptFromRequest

func (kv *CryptKV) DecryptFromRequest(r *http.Request, k string) (string, error)

Decrypt from http.Request

func (*CryptKV) Encrypt

func (kv *CryptKV) Encrypt(k string, v string) (string, error)

Encrypt key, value

type Dial

type Dial struct {
	Timeout time.Duration
}

DefaultDial is the default dialer which dial with tcp network

func (*Dial) Dial

func (d *Dial) Dial(network, addr string) (net.Conn, error)

Dial a remote address

type Dialer

type Dialer interface {
	Dial(network, addr string) (net.Conn, error)
}

Dialer is a common interface for dialing

type SafeMap

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

SafeMap is concurrent security map

func NewSafeMap

func NewSafeMap() *SafeMap

NewSafeMap get a new concurrent security map

func (*SafeMap) Delete

func (m *SafeMap) Delete(k interface{})

Delete used to delete a key

func (*SafeMap) Get

func (m *SafeMap) Get(k interface{}) interface{}

Get used to get a value by key

func (*SafeMap) IsExists

func (m *SafeMap) IsExists(k interface{}) bool

IsExists determine whether k exists

func (*SafeMap) Set

func (m *SafeMap) Set(k interface{}, v interface{}) bool

Set used to set value with key

type Slack

type Slack struct {
	URL      string
	Channel  string
	UserName string
	IconURL  string
}

func (*Slack) Send

func (sl *Slack) Send(data interface{}, cui ...string) error

Send data to slack channel data must be one of map[string]string, map[string]interface{}, string, []string, struct cui is channel like #general, username, icon_url

Jump to

Keyboard shortcuts

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