base

package module
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 28 Imported by: 20

README

base

base

Documentation

Index

Constants

View Source
const (
	En   = `en`
	ZhTw = `zh-tw`
	ZhCn = `zh_CN`
)
View Source
const (
	ModeWait    = 1
	ModeMaxTime = 2
	ModeError   = 3
)

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 (
	ErrIpV4Address = errors.New(`invalid ip v4 address`)
	ErrNotFoundIp  = errors.New("not found ip address")
)
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 (
	ErrOutOfRange = errors.New("out of range")
	ErrTimeBack   = errors.New("time go back")
	ErrMachineId  = errors.New("illegal machine id")
	ErrLogicId    = errors.New("illegal logic id")
)
View Source
var ErrNoServer = errors.New("no server")
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 LocalIp added in v1.0.8

func LocalIp() (ip string, 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 RedFatal added in v1.0.8

func RedFatal(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 GetMachineId added in v1.0.8

type GetMachineId func() (id int64, err error)

func GetMachineIdByEnv added in v1.0.8

func GetMachineIdByEnv(key string) GetMachineId

func GetMachineIdByIp added in v1.0.8

func GetMachineIdByIp() GetMachineId

type HashRing added in v1.0.9

type HashRing interface {
	Store(servers ...CanHash)
	Get(key interface{}) (server CanHash, err error)
	Add(server CanHash)
	Remove(server CanHash)
	Length() int
	Range(handler func(index int, server CanHash) (handled bool))
}

func NewHashRing added in v1.0.9

func NewHashRing(servers ...CanHash) HashRing

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 Node added in v1.0.9

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

type NodeList added in v1.0.9

type NodeList []Node

func (NodeList) Len added in v1.0.9

func (n NodeList) Len() int

func (NodeList) Less added in v1.0.9

func (n NodeList) Less(i, j int) bool

func (NodeList) Swap added in v1.0.9

func (n NodeList) Swap(i, j int)

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

type SnowFlake added in v1.0.8

type SnowFlake interface {
	Id(logicId uint8) (int64, error)
	Info(id int64) (timestamp int64, machineId uint8, logicId uint8, index int16)
}

func NewSF added in v1.0.8

func NewSF(mode uint8, id uint8, timeStampBegin int64) (sfl SnowFlake, err error)

func NewSFByIp added in v1.0.8

func NewSFByIp(mode uint8, timeStampBegin int64) (sfl SnowFlake, err error)

func NewSFByMachineFunc added in v1.0.8

func NewSFByMachineFunc(mode uint8, machindFunc GetMachineId, timeStampBegin int64) (sfl SnowFlake, err error)

Directories

Path Synopsis
examples
i18n command

Jump to

Keyboard shortcuts

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