base

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2021 License: MIT Imports: 24 Imported by: 20

README

base

base

Documentation

Index

Constants

View Source
const (
	En   = `en`
	ZhTw = `zh-tw`
	ZhCn = `zh_CN`
)

Variables

View Source
var (
	ErrInvalidPaddingChar = errors.New(`invalid padding char`)
	ErrAesDecrypt         = errors.New(`aes decrypt error`)
)
View Source
var (
	ErrMsgMapEmpty = errors.New("msgMap can not empty")
	ErrNoYamlFiles = errors.New("there are no `.yml` or `.yaml` files in this directory")
	ErrNoJsonFiles = errors.New("there are no `.json` files in this directory")
)
View Source
var (
	AcquireArgs = func() []interface{} {
		return argsPool.Get().([]interface{})
	}

	ReleaseArgs = func(args *[]interface{}) {
		if args == nil {
			return
		}

		*args = (*args)[:0]
		argsPool.Put(*args)
	}
)
View Source
var (
	ErrIpV4Address = errors.New(`invalid ip v4 address`)
)
View Source
var (
	SetValue = struct{}{}
)

Functions

func Black added in v1.0.3

func Black(format string, args ...interface{})

func Blue added in v1.0.3

func Blue(format string, args ...interface{})

func Bytes2Int64 added in v1.0.7

func Bytes2Int64(data []byte) int64

func Bytes2String added in v1.0.7

func Bytes2String(data []byte) string

func CreatePkcs1Keys added in v1.0.6

func CreatePkcs1Keys(keyLength int) (privateKey, publicKey string)

*

  • 生成pkcs1格式公钥私钥

func CreatePkcs8Keys added in v1.0.3

func CreatePkcs8Keys(keyLength int) (privateKey, publicKey string)

*

  • 生成pkcs8格式公钥私钥

func Fuchsia added in v1.0.3

func Fuchsia(format string, args ...interface{})

func Green added in v1.0.3

func Green(format string, args ...interface{})

func HMac added in v1.0.3

func HMac(key []byte, data []byte, hash crypto.Hash) string

func Hash added in v1.0.3

func Hash(data []byte, hash crypto.Hash) string

func HashValue

func HashValue(key interface{}) uint32

func Index4Bit

func Index4Bit(key interface{}, bitCount uint8) uint32

func Index4Int16

func Index4Int16(key interface{}) int16

func Index4Int8

func Index4Int8(key interface{}) int8

func Index4Uint8

func Index4Uint8(key interface{}) uint8

func Ip2Long

func Ip2Long(ip string) (ipVal uint32, err error)

func JsonDecode

func JsonDecode(data []byte, v interface{}) (err error)

func JsonDecodeFile

func JsonDecodeFile(filePath string, v interface{}) (err error)

func JsonEncode

func JsonEncode(v interface{}) (data []byte, err error)

func Long2Ip

func Long2Ip(ipVal uint32) string

func MarshalPkcs8PrivateKey added in v1.0.6

func MarshalPkcs8PrivateKey(key *rsa.PrivateKey) []byte

func Md5 added in v1.0.3

func Md5(data []byte) string

func Red added in v1.0.3

func Red(format string, args ...interface{})

func Sha1 added in v1.0.3

func Sha1(data []byte) string

func YamlDecode

func YamlDecode(data []byte, v interface{}) (err error)

func YamlDecodeFile

func YamlDecodeFile(filePath string, v interface{}) (err error)

func YamlEncode

func YamlEncode(v interface{}) (data []byte, err error)

func Yellow added in v1.0.3

func Yellow(format string, args ...interface{})

Types

type Aes added in v1.0.3

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

func NewAes added in v1.0.3

func NewAes(key string, iv string) (a *Aes, err error)

func (*Aes) CbcDecrypt added in v1.0.3

func (a *Aes) CbcDecrypt(secretData []byte) (data []byte, err error)

func (*Aes) CbcEncrypt added in v1.0.3

func (a *Aes) CbcEncrypt(plain []byte) (secretData []byte)

type Bitmap

type Bitmap interface {
	HasBit() bool
	BitCount() int
	Exists(tag int) (exists bool)
	AddTag(tag int) Bitmap
	DelTag(tag int) Bitmap
	SprinfBinary() string
}

func NewBitmap

func NewBitmap(data []byte) Bitmap

type CanHash

type CanHash interface {
	HashCode() (hashValue uint32)
}

type HashSet

type HashSet interface {
	Add(items ...interface{}) (newNum int)
	Delete(items ...interface{}) (delNum int)
	Exists(item interface{}) (exists bool)
	Length() (length int)
}

func NewHashSet

func NewHashSet(size int) HashSet

type I18n added in v1.0.3

type I18n interface {
	T(key, language string) (msg string)
}

func NewI18n added in v1.0.3

func NewI18n(defaultLanguage string, msgMap map[string]map[string]string) (i I18n, err error)

func NewI18nFromJson added in v1.0.3

func NewI18nFromJson(defaultLanguage string, dir string) (i I18n, err error)

func NewI18nFromYaml added in v1.0.3

func NewI18nFromYaml(defaultLanguage string, dir string) (i I18n, err error)

type Msg

type Msg struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func (*Msg) Json

func (m *Msg) Json() (msg []byte)

type Rsa added in v1.0.3

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

func NewRsa added in v1.0.3

func NewRsa(publicKey, privateKey string) (r *Rsa, err error)

func NewRsaWithPkcs1 added in v1.0.6

func NewRsaWithPkcs1(publicKey, privateKey string) (r *Rsa, err error)

func NewRsaWithPkcs8 added in v1.0.6

func NewRsaWithPkcs8(publicKey, privateKey string) (r *Rsa, err error)

func (*Rsa) Decrypt added in v1.0.3

func (r *Rsa) Decrypt(secretData []byte) ([]byte, error)

*

  • 解密

func (*Rsa) Encrypt added in v1.0.3

func (r *Rsa) Encrypt(data []byte) ([]byte, error)

*

  • 加密

func (*Rsa) Sign added in v1.0.3

func (r *Rsa) Sign(data []byte, algorithmSign crypto.Hash) ([]byte, error)

*

  • 签名

func (*Rsa) Verify added in v1.0.3

func (r *Rsa) Verify(data []byte, sign []byte, algorithmSign crypto.Hash) bool

*

  • 验签

type ShardMap

type ShardMap interface {
	Set(key interface{}, value interface{})
	Get(key interface{}) (value interface{}, exists bool)
	Exists(key interface{}) (exists bool)
	Delete(keys ...interface{})
	Length() int64
}

func NewShardMap

func NewShardMap() ShardMap

Directories

Path Synopsis
examples
i18n command

Jump to

Keyboard shortcuts

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