base

package module
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: MIT Imports: 51 Imported by: 20

README

base

base

Documentation

Index

Constants

View Source
const (
	LevelJson = 0
	LevelV1   = 1
	LevelV2   = 2
)
View Source
const (
	// OK 成功返回
	OK = codes.OK

	// CodeCanceled 表示操作已取消(通常由调用者取消)
	CodeCanceled = codes.Canceled

	// CodeUnknown 未知错误
	CodeUnknown = codes.Unknown

	// CodeInvalidArgument 客户端传递了一个无效的参数
	CodeInvalidArgument = codes.InvalidArgument

	// CodeDeadlineExceeded 表示操作在完成前过期。对于改变系统状态的操作,即使操作成功完成,也可能会返回此错误。
	// 例如,来自服务器的成功响应可能已延迟足够长的时间以使截止日期到期
	CodeDeadlineExceeded = codes.DeadlineExceeded

	// CodeNotFound 表示未找到某些请求的实体(例如文件或目录)
	CodeNotFound = codes.NotFound

	// CodeAlreadyExists 表示创建实体的尝试失败,因为实体已经存在
	CodeAlreadyExists = codes.AlreadyExists

	// CodePermissionDenied 表示调用者没有执行指定操作的权限
	CodePermissionDenied = codes.PermissionDenied

	// CodeResourceExhausted 表示某些资源已用尽,可能是每个用户的配额,或者可能是整个文件系统空间不足
	CodeResourceExhausted = codes.ResourceExhausted

	// CodeFailedPrecondition 操作被拒绝,因为系统未处于操作执行所需的状态。
	// 例如,要删除的目录可能是非空的,rmdir 操作应用于非目录等
	CodeFailedPrecondition = codes.FailedPrecondition

	// CodeAborted 操作已取消,通常是由于并发问题,如排序器检查失败、事务中止
	CodeAborted = codes.Aborted

	// CodeOutRange 超出范围的操作
	CodeOutRange = codes.OutOfRange

	// CodeUnimplemented 未实现或不支持的操作
	CodeUnimplemented = codes.Unimplemented

	// CodeInternal 系统内部错误
	CodeInternal = codes.Internal

	// CodeUnavailable 表示该服务当前不可用。这很可能是一种瞬态情况,可以通过回退重试来纠正。
	// 请注意,重试非幂等操作是不安全的
	CodeUnavailable = codes.Unavailable

	// CodeDataLoss 表示不可恢复的数据丢失或损坏
	CodeDataLoss = codes.DataLoss

	// CodeUnauthenticated 表示请求没有用于操作的有效身份验证凭据
	CodeUnauthenticated = codes.Unauthenticated
)
View Source
const (
	EnvPro  = `pro`
	EnvDev  = `dev`
	EnvTest = `test`
)
View Source
const (
	EventConnectSuccess = 0x0100
	EventTick           = 0x0101
	EventClose          = 0x0102
	EventError          = 0x0103
	EventLogin          = 0x0200
	EventLoginSuccess   = 0x0201
	EventLoginFailed    = 0x0202
)
View Source
const (
	ModeWait    = 1
	ModeMaxTime = 2
	ModeError   = 3
)
View Source
const (
	StateIndexMax = 30
)
View Source
const (
	ZhCn = `zh_CN`
)

Variables

View Source
var (
	ErrInvalidPaddingChar = NewError(CodeInvalidArgument, `invalid padding char`)
	ErrAesDecrypt         = NewError(CodeInvalidArgument, `aes decrypt error`)
)
View Source
var (
	ErrForbidden          = NewBError(CodePermissionDenied, "permissin denied")
	ErrDataEmpty          = NewBError(CodeDataLoss, "data is empty")
	ErrKeyFormat          = NewBError(CodeInvalidArgument, "invalid key format")
	ErrDataFormat         = NewBError(CodeInvalidArgument, "invalid data format")
	ErrDataSign           = NewBError(CodePermissionDenied, "invalid data sign")
	ErrState              = NewBError(CodeOutRange, "state index must lte 30")
	ErrOutOfRange         = NewBError(CodeOutRange, "out of range")
	ErrAlphanumeric       = NewBError(CodeInvalidArgument, "alphanumeric must be [a-zA-Z0-9] and not repeat")
	ErrAlphanumericLength = NewBError(CodeInvalidArgument, "alphanumeric length must be [50, 62]")
	ErrTimeBack           = NewBError(CodeInternal, "time go back")
	ErrMachineId          = NewBError(CodeInvalidArgument, "illegal machine id")
)
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 (
	JsonMarshal   = jsoniter.Marshal
	JsonUnmarshal = jsoniter.Unmarshal
)
View Source
var (

	// AcquireArgs 获取参数
	AcquireArgs = func() []interface{} {
		return argsPool.Get().([]interface{})
	}

	// ReleaseArgs 释放参数
	ReleaseArgs = func(args *[]interface{}) {
		if args == nil {
			return
		}

		*args = (*args)[:0]
		argsPool.Put(*args)
	}
)
View Source
var (
	YamlMarshal   = yaml.Marshal
	YamlUnmarshal = yaml.Unmarshal
)
View Source
var (
	DefaultContainer = &Container{}
)
View Source
var ErrNoServer = errors.New("no server")
View Source
var (
	ErrNotTcpListener = NewError(CodeInvalidArgument, "listener is not tcp listener")
)
View Source
var (
	SetValue = struct{}{}
)

Functions

func AbsInt added in v1.3.7

func AbsInt(value int) int

func AbsInt16 added in v1.3.7

func AbsInt16(value int16) int16

func AbsInt32 added in v1.3.7

func AbsInt32(value int32) int32

func AbsInt64 added in v1.3.7

func AbsInt64(value int64) int64

func AbsInt8 added in v1.3.7

func AbsInt8(value int8) int8

func BigCamels added in v1.0.20

func BigCamels(sep byte, data string) string

BigCamels 转换为大驼峰

func BinPath added in v1.1.5

func BinPath() string

BinPath 获取Bin目录

func Black added in v1.0.3

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

Black 默认输出

func Blue added in v1.0.3

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

Blue 颜色输出

func Bytes2Float64 added in v1.0.12

func Bytes2Float64(data []byte) float64

Bytes2Float64 字节切片转换为float64

func Bytes2Int64 added in v1.0.7

func Bytes2Int64(data []byte) int64

Bytes2Int64 字节切片转换为int64

func Bytes2String added in v1.0.7

func Bytes2String(data []byte) string

Bytes2String 字节切片转换为字符串

func Bytes2Uint32 added in v1.2.5

func Bytes2Uint32(data []byte) uint32

Bytes2Uint32 字节切片转换为uint32

func Bytes2Uint64 added in v1.2.18

func Bytes2Uint64(data []byte) uint64

Bytes2Uint64 字节切片转换为uint64

func CreatePkcs1Keys added in v1.0.6

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

CreatePkcs1Keys 生成pkcs1格式公钥私钥

func CreatePkcs8Keys added in v1.0.3

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

CreatePkcs8Keys 生成pkcs8格式公钥私钥

func DPanic added in v1.2.5

func DPanic(msg string, fields ...zap.Field)

func Debug added in v1.0.21

func Debug(msg string, fields ...zap.Field)

func Error added in v1.0.21

func Error(msg string, fields ...zap.Field)

func Fatal added in v1.0.21

func Fatal(msg string, fields ...zap.Field)

func FileExists added in v1.0.22

func FileExists(fileName string) bool

FileExists 判断文件是否存在

func Fuchsia added in v1.0.3

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

Fuchsia 颜色输出

func Green added in v1.0.3

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

Green 成功输出

func HMac added in v1.0.3

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

HMac HMac算法

func Hash added in v1.0.3

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

Hash Hash算法

func HashValue

func HashValue(key interface{}) uint32

HashValue 计算任意类型hash值

func Hex2Int64 added in v1.2.6

func Hex2Int64(value string) int64

Hex2Int64 _

func Hex2Uint64 added in v1.2.7

func Hex2Uint64(value string) uint64

Hex2Uint64 _

func Index4Bit

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

Index4Bit 索引路由方法,值范围为uint32

func Index4Int16

func Index4Int16(key interface{}) int16

Index4Int16 索引路由方法,值范围为int16

func Index4Int8

func Index4Int8(key interface{}) int8

Index4Int8 索引路由方法,值范围为int8

func Index4Uint8

func Index4Uint8(key interface{}) uint8

Index4Uint8 索引路由方法,值范围为uint8

func Info added in v1.0.21

func Info(msg string, fields ...zap.Field)

func InitZapWithOption added in v1.2.5

func InitZapWithOption(conf zaplogger.Option, zapOpts ...zap.Option) error

func Int64ToHex added in v1.2.6

func Int64ToHex(value int64) string

Int64ToHex _

func Int64ToHexWithPad added in v1.2.6

func Int64ToHexWithPad(value int64, padLength int) string

Int64ToHexWithPad _

func Ip2Long

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

Ip2Long Ip转换为uint32

func IsLevel added in v1.2.5

func IsLevel(level zapcore.Level) bool

func JoinInt added in v1.2.21

func JoinInt(sep string, elems ...int) string

func JoinInt16 added in v1.2.21

func JoinInt16(sep string, elems ...int16) string

func JoinInt32 added in v1.2.21

func JoinInt32(sep string, elems ...int32) string

func JoinInt64 added in v1.2.21

func JoinInt64(sep string, elems ...int64) string

func JoinInt8 added in v1.2.21

func JoinInt8(sep string, elems ...int8) string

func JoinUint added in v1.2.21

func JoinUint(sep string, elems ...uint) string

func JoinUint16 added in v1.2.21

func JoinUint16(sep string, elems ...uint16) string

func JoinUint32 added in v1.2.21

func JoinUint32(sep string, elems ...uint32) string

func JoinUint64 added in v1.2.21

func JoinUint64(sep string, elems ...uint64) string

func JoinUint8 added in v1.2.21

func JoinUint8(sep string, elems ...uint8) string

func JsonDecode

func JsonDecode(data string, v interface{}) (err error)

JsonDecode ---

func JsonDecodeFile

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

JsonDecodeFile ---

func JsonEncode

func JsonEncode(v interface{}) (data string, err error)

JsonEncode ---

func LcFirst added in v1.2.18

func LcFirst(str string) string

func LocalIp added in v1.0.8

func LocalIp() (ip string, err error)

LocalIp 获取本机Ip

func Long2Ip

func Long2Ip(ipVal uint32) string

Long2Ip uint32转换为Ip

func MarshalPkcs8PrivateKey added in v1.0.6

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

func Max6 added in v1.3.8

func Max6() int64

func Max8 added in v1.3.8

func Max8() int64

func Md5 added in v1.0.3

func Md5(data []byte) string

Md5 Md5算法

func NewError added in v1.2.19

func NewError(code codes.Code, msg string) error

func NewGoPool added in v1.1.5

func NewGoPool(size int, opts ...gopool.Option) (*gopool.Pool, error)

NewGoPool 实例化goroutine池

func NewIdCode added in v1.3.8

func NewIdCode(alphanumericSet []byte, salt6, salt8 int64) (*IdCode, *BError)

func PackIn32 added in v1.2.11

func PackIn32(value int32) []byte

func PackUin32 added in v1.2.11

func PackUin32(value uint32) []byte

func Panic added in v1.0.21

func Panic(msg string, fields ...zap.Field)

func PprofIsRun added in v1.2.6

func PprofIsRun() bool

PprofIsRun _

func RandBytes added in v1.2.7

func RandBytes(length int) []byte

func Recover added in v1.3.1

func Recover(eventName string, f func())

func Red added in v1.0.3

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

Red 错误输出

func RedFatal added in v1.0.8

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

RedFatal 致命错误输出

func Sha1 added in v1.0.3

func Sha1(data []byte) string

Sha1 Sha1算法

func SmallCamels added in v1.0.20

func SmallCamels(sep byte, data string) string

SmallCamels 转换为小驼峰

func StartPprof added in v1.2.6

func StartPprof(addr string, handler http.Handler) error

StartPprof _

func StopPprof added in v1.2.6

func StopPprof(ctx context.Context) error

StopPprof _

func StopPprofWithTimeout added in v1.3.0

func StopPprofWithTimeout(seconds int64) error

StopPprofWithTimeout _

func ToString added in v1.1.5

func ToString(val interface{}) string

ToString 转为字符串类型

func UcFirst added in v1.2.18

func UcFirst(str string) string

func Uint64ToHex added in v1.2.7

func Uint64ToHex(value uint64) string

Uint64ToHex _

func UnpackInt32 added in v1.2.11

func UnpackInt32(data []byte) (value int32, err error)

func UnpackUint32 added in v1.2.11

func UnpackUint32(data []byte) (value uint32, err error)

func Warn added in v1.0.21

func Warn(msg string, fields ...zap.Field)

func WorkWithAffinity added in v1.2.26

func WorkWithAffinity(id int) (uint64, error)

WorkWithAffinity 绑定CPU

func YamlDecode

func YamlDecode(data string, v interface{}) (err error)

YamlDecode ---

func YamlDecodeFile

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

YamlDecodeFile ---

func YamlEncode

func YamlEncode(v interface{}) (data string, err error)

YamlEncode ---

func Yellow added in v1.0.3

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

Yellow 警告输出

func ZapDPanic added in v1.2.5

func ZapDPanic(msg string, fields ...zap.Field)

func ZapDebug added in v1.0.21

func ZapDebug(msg string, fields ...zap.Field)

func ZapError added in v1.0.21

func ZapError(msg string, fields ...zap.Field)

func ZapFatal added in v1.0.21

func ZapFatal(msg string, fields ...zap.Field)

func ZapInfo added in v1.0.21

func ZapInfo(msg string, fields ...zap.Field)

func ZapPanic added in v1.0.21

func ZapPanic(msg string, fields ...zap.Field)

func ZapSync added in v1.0.21

func ZapSync() error

func ZapWarn added in v1.0.21

func ZapWarn(msg string, fields ...zap.Field)

Types

type Accept added in v1.2.7

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

func NewAccept added in v1.2.7

func NewAccept(aes *Aes, level uint8) *Accept

func (*Accept) Accept added in v1.2.7

func (a *Accept) Accept(level uint8, secretData []byte) (protocol Protocol, err error)

func (*Accept) AcceptBase64Url added in v1.2.7

func (a *Accept) AcceptBase64Url(level uint8, base64Data []byte, urlSafe bool) (protocol Protocol, err error)

func (*Accept) AcceptHex added in v1.2.7

func (a *Accept) AcceptHex(level uint8, hexData []byte) (protocol Protocol, err error)

type Aes added in v1.0.3

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

Aes Aes加密

func NewAes added in v1.0.3

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

NewAes 实例化Aes

func NewAesWithBytes added in v1.1.4

func NewAesWithBytes(key, iv []byte) (a *Aes, err error)

NewAesWithBytes 实例化Aes

func (*Aes) CbcDecrypt added in v1.0.3

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

CbcDecrypt cbc解密

func (*Aes) CbcEncrypt added in v1.0.3

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

CbcEncrypt cbc加密

type BError added in v1.3.4

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

func Code2Id added in v1.3.8

func Code2Id(code []byte) (id int64, err *BError)

func Code6 added in v1.3.8

func Code6(id int64) (code []byte, err *BError)

func Code6String added in v1.3.8

func Code6String(id int64) (code string, err *BError)

func Code6To8 added in v1.3.8

func Code6To8(code6 []byte) (code8 []byte, err *BError)

func Code8 added in v1.3.8

func Code8(id int64) (code []byte, err *BError)

func Code8String added in v1.3.8

func Code8String(id int64) (code string, err *BError)

func CodeString2Id added in v1.3.8

func CodeString2Id(code string) (id int64, err *BError)

func CodeString6To8 added in v1.3.8

func CodeString6To8(code6 string) (code8 string, err *BError)

func NewBError added in v1.3.5

func NewBError(code codes.Code, msg string) *BError

func (*BError) Clone added in v1.3.5

func (be *BError) Clone() *BError

func (*BError) Code added in v1.3.4

func (be *BError) Code() codes.Code

func (*BError) Equal added in v1.3.5

func (be *BError) Equal(target error) bool

func (*BError) Error added in v1.3.4

func (be *BError) Error() string

func (*BError) Is added in v1.3.4

func (be *BError) Is(target error) bool

func (*BError) JsonMarshal added in v1.3.4

func (be *BError) JsonMarshal() []byte

func (*BError) ToStatus added in v1.3.4

func (be *BError) ToStatus() *Status

func (*BError) WithFlag added in v1.3.4

func (be *BError) WithFlag(flag uint8) *BError

type Bitmap

type Bitmap interface {
	// HasBit 是否有值
	HasBit() bool
	// BitCount 值的数量
	BitCount() int
	// Exists 标签是否存在
	Exists(tag int) (exists bool)
	// AddTag 添加标签
	AddTag(tag int) Bitmap
	// DelTag 删除标签
	DelTag(tag int) Bitmap
	// Data 原始数据
	Data() (data []byte)
	// SprinfBinary 二进制打印
	SprinfBinary() string
}

Bitmap bitmap数据结构

func NewBitmap

func NewBitmap(data []byte) Bitmap

type CanHash

type CanHash interface {
	// HashCode 计算hash值
	HashCode() (hashValue uint32)
}

CanHash hash接口

type Config added in v1.2.5

type Config struct {
	Name      string           `json:"name" yaml:"name"`
	Addr      string           `json:"addr" yaml:"addr"`
	PprofAddr string           `json:"pprofAddr" yaml:"pprofAddr"`
	Env       string           `json:"env" yaml:"env"`
	Ver       string           `json:"ver" yaml:"ver"`
	Logger    zaplogger.Option `json:"logger" yaml:"logger"`
	Params    JsonParam        `json:"params" yaml:"params"`
}

func (*Config) IsEnv added in v1.2.5

func (c *Config) IsEnv(env string) bool

type Container added in v1.2.5

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

func (*Container) Config added in v1.2.5

func (c *Container) Config() *Config

Config 获取配置文件

func (*Container) Get added in v1.2.5

func (c *Container) Get(key string) (value interface{}, exists bool)

Get 从容器中获取值

func (*Container) Set added in v1.2.5

func (c *Container) Set(key string, value interface{})

Set 向容器中写入值

func (*Container) SetConfig added in v1.2.5

func (c *Container) SetConfig(value *Config)

SetConfig 修改配置

type Context added in v1.1.3

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

Context 上下文

func AcquireCtx added in v1.1.3

func AcquireCtx(handlers []func(ctx *Context)) *Context

AcquireCtx 申请Context

func (*Context) Abort added in v1.1.3

func (c *Context) Abort()

func (*Context) Close added in v1.1.3

func (c *Context) Close()

Close 释放Context

func (*Context) Deadline added in v1.1.3

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done added in v1.1.3

func (c *Context) Done() <-chan struct{}

func (*Context) Err added in v1.1.3

func (c *Context) Err() error

func (*Context) Get added in v1.1.3

func (c *Context) Get(key string) (value interface{}, exists bool)

Get 获取数据

func (*Context) GetBool added in v1.1.3

func (c *Context) GetBool(key string) (value bool, exists bool)

GetBool 获取bool值

func (*Context) GetInt added in v1.1.3

func (c *Context) GetInt(key string) (value int, exists bool)

GetInt 获取int值

func (*Context) GetInt64 added in v1.1.3

func (c *Context) GetInt64(key string) (value int64, exists bool)

GetInt64 获取int64值

func (*Context) GetInt8 added in v1.1.3

func (c *Context) GetInt8(key string) (value int8, exists bool)

GetInt8 获取bool值

func (*Context) GetString added in v1.1.3

func (c *Context) GetString(key string) (value string, exists bool)

GetString 获取string值

func (*Context) IsAborted added in v1.1.3

func (c *Context) IsAborted() bool

func (*Context) Next added in v1.1.3

func (c *Context) Next()

func (*Context) Set added in v1.1.3

func (c *Context) Set(key string, value interface{})

Set 存储数据

func (*Context) Value added in v1.1.3

func (c *Context) Value(key interface{}) interface{}

type GetMachineId added in v1.0.8

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

GetMachineId 获取机器Id

func GetMachineIdByEnv added in v1.0.8

func GetMachineIdByEnv(key string) GetMachineId

GetMachineIdByEnv 根据环境变量获取机器Id

func GetMachineIdByIp added in v1.0.8

func GetMachineIdByIp() GetMachineId

GetMachineIdByIp 根据Ip获取机器Id

type GracefulHttp added in v1.2.25

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

func NewGracefulHttp added in v1.2.25

func NewGracefulHttp(server *http.Server) *GracefulHttp

func (*GracefulHttp) HandlerSig added in v1.2.25

func (hs *GracefulHttp) HandlerSig(pprofAddr string, timeoutSecond int64)

func (*GracefulHttp) Listen added in v1.2.25

func (hs *GracefulHttp) Listen() (err error)

func (*GracefulHttp) Reload added in v1.2.25

func (hs *GracefulHttp) Reload() (pid int, err error)

func (*GracefulHttp) Shutdown added in v1.2.25

func (hs *GracefulHttp) Shutdown(ctx context.Context) error

func (*GracefulHttp) ShutdownWithTimeout added in v1.2.25

func (hs *GracefulHttp) ShutdownWithTimeout(timeoutSecond int64) error

type HashRing added in v1.0.9

type HashRing interface {
	// Store 存储servers
	Store(servers ...CanHash)
	// Get 获取server
	Get(key interface{}) (server CanHash, err error)
	// Index 根据index获取server
	Index(index int) (server CanHash, err error)
	// Add 添加server
	Add(server CanHash)
	// Remove 移除server
	Remove(server CanHash)
	// Length 获取servers长度
	Length() int
	// Range 遍历servers
	Range(handler func(index int, server CanHash, hitCount uint64) (handled bool))
}

HashRing Hash环

func NewHashRing added in v1.0.9

func NewHashRing(servers ...CanHash) HashRing

type HashSet

type HashSet interface {
	// Add 添加元素
	Add(items ...interface{}) (newNum int)
	// Delete 删除元素
	Delete(items ...interface{}) (delNum int)
	// Exists 元素是否存在
	Exists(item interface{}) (exists bool)
	// Length 长度
	Length() (length int)
}

HashSet 接口

func NewHashSet

func NewHashSet(size int) HashSet

NewHashSet 实例化HashSet

type I18n added in v1.0.3

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

I18n 多语言接口

func NewI18n added in v1.0.3

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

NewI18n 实例化多语言

func NewI18nFromJson added in v1.0.3

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

NewI18nFromJson 从Json文件配置实例化多语言

func NewI18nFromYaml added in v1.0.3

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

NewI18nFromYaml 从Yaml文件配置实例化多语言

type IdCode added in v1.3.8

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

func (*IdCode) Code2Id added in v1.3.8

func (ic *IdCode) Code2Id(code []byte) (id int64, err *BError)

func (*IdCode) Code6 added in v1.3.8

func (ic *IdCode) Code6(id int64) (code []byte, err *BError)

func (*IdCode) Code6String added in v1.3.8

func (ic *IdCode) Code6String(id int64) (code string, err *BError)

func (*IdCode) Code6To8 added in v1.3.8

func (ic *IdCode) Code6To8(code6 []byte) (code8 []byte, err *BError)

func (*IdCode) Code8 added in v1.3.8

func (ic *IdCode) Code8(id int64) (code []byte, err *BError)

func (*IdCode) Code8String added in v1.3.8

func (ic *IdCode) Code8String(id int64) (code string, err *BError)

func (*IdCode) CodeString2Id added in v1.3.8

func (ic *IdCode) CodeString2Id(code string) (id int64, err *BError)

func (*IdCode) CodeString6To8 added in v1.3.8

func (ic *IdCode) CodeString6To8(code6 string) (code8 string, err *BError)

func (*IdCode) Max6 added in v1.3.8

func (ic *IdCode) Max6() int64

func (*IdCode) Max8 added in v1.3.8

func (ic *IdCode) Max8() int64

type JsonParam added in v1.2.1

type JsonParam map[string]interface{}

func UnmarshalJsonParam added in v1.2.1

func UnmarshalJsonParam(data []byte) (JsonParam, error)

UnmarshalJsonParam _

func (JsonParam) Exists added in v1.2.1

func (jp JsonParam) Exists(key string) bool

Exists key是否存在,返回bool值

func (JsonParam) Float64 added in v1.2.1

func (jp JsonParam) Float64(key string) float64

Float64 获取float64,如果不是float64,返回0

func (JsonParam) Int added in v1.2.1

func (jp JsonParam) Int(key string) int

Int 获取Int,如果不是int,返回0

func (JsonParam) Int64 added in v1.2.1

func (jp JsonParam) Int64(key string) int64

Int64 获取Int64,如果不是float64,返回0

func (JsonParam) Int64Slice added in v1.2.1

func (jp JsonParam) Int64Slice(key string) []int64

Int64Slice 获取[]int64,获取失败返回nil

func (JsonParam) IntSlice added in v1.2.1

func (jp JsonParam) IntSlice(key string) []int

IntSlice 获取[]int,获取失败,返回nil

func (JsonParam) JsonMarshal added in v1.2.1

func (jp JsonParam) JsonMarshal() []byte

JsonMarshal _

func (JsonParam) String added in v1.2.1

func (jp JsonParam) String(key string) string

String 获取string值,如果不是string类型,返回""

func (JsonParam) StringSlice added in v1.2.1

func (jp JsonParam) StringSlice(key string) []string

StringSlice 获取[]string,如果不是[]string返回nil

func (JsonParam) Uint32Slice added in v1.2.1

func (jp JsonParam) Uint32Slice(key string) []uint32

Uint32Slice 获取[]uint32,获取失败返回nil

type Mysql added in v1.2.22

type Mysql struct {
	*sql.DB
	Options MysqlOption
}

func NewMysql added in v1.2.22

func NewMysql(opt MysqlOption) (mysql *Mysql, err error)

type MysqlOption added in v1.2.22

type MysqlOption struct {
	DbName                string `json:"dbName" yaml:"dbName"`
	Host                  string `json:"host" yaml:"host"`
	Port                  uint32 `json:"port" yaml:"port"`
	UserName              string `json:"userName" yaml:"userName"`
	Password              string `json:"password" yaml:"password"`
	CharSet               string `json:"charSet" yaml:"charSet"`
	MaxIdleConns          int    `json:"maxIdleConns" yaml:"maxIdleConns"`
	MaxOpenConns          int    `json:"maxOpenConns" yaml:"maxOpenConns"`
	ConnMaxIdleTimeSecond int64  `json:"connMaxIdleTimeSecond" yaml:"connMaxIdleTimeSecond"`
	ConnMaxLifetimeSecond int64  `json:"connMaxLifetimeSecond" yaml:"connMaxLifetimeSecond"`
}

func DefaultMysqlOption added in v1.2.22

func DefaultMysqlOption() MysqlOption

func MysqlOptionWithJson added in v1.2.22

func MysqlOptionWithJson(conf string) (opt MysqlOption, err error)

func MysqlOptionWithYaml added in v1.2.22

func MysqlOptionWithYaml(conf string) (opt MysqlOption, err error)

func (*MysqlOption) Dsn added in v1.2.22

func (mo *MysqlOption) Dsn() string

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 Package added in v1.2.6

type Package struct {
	Id    uint16    `json:"id"`
	Name  string    `json:"name"`
	Param JsonParam `json:"param"`
}

func (*Package) Pack added in v1.2.6

func (p *Package) Pack() []byte

func (*Package) Unpack added in v1.2.6

func (p *Package) Unpack(data []byte) error

type Protocol added in v1.2.7

type Protocol interface {
	Pack(pkg *Package) []byte
	ResponseKey() []byte
	Unpack(data []byte) (pkg *Package, err error)
}

func NewV0 added in v1.2.7

func NewV0() (protocol Protocol, err error)

func NewV1 added in v1.2.6

func NewV1(aes *Aes, secretData []byte) (protocol Protocol, err error)

func NewV2 added in v1.2.7

func NewV2(aes *Aes, secretData []byte) (protocol Protocol, err error)

func NewV2ForClient added in v1.2.9

func NewV2ForClient(aes *Aes, key, secretData []byte) (protocol Protocol, err error)

type Rsa added in v1.0.3

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

Rsa Rsa

func NewRsa added in v1.0.3

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

NewRsa 实例化Rsa

func NewRsaBytes added in v1.2.20

func NewRsaBytes(public, private []byte) (r *Rsa, err error)

NewRsaBytes 实例化Rsa

func NewRsaWithPkcs1 added in v1.0.6

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

NewRsaWithPkcs1 pkcs1实例化Rsa

func NewRsaWithPkcs1Bytes added in v1.2.20

func NewRsaWithPkcs1Bytes(public, private []byte) (r *Rsa, err error)

NewRsaWithPkcs1Bytes pkc1实例化Rsa

func NewRsaWithPkcs8 added in v1.0.6

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

NewRsaWithPkcs8 pkcs8实例化Rsa

func NewRsaWithPkcs8Bytes added in v1.2.20

func NewRsaWithPkcs8Bytes(public, private []byte) (r *Rsa, err error)

func (*Rsa) Decrypt added in v1.0.3

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

Decrypt 解密

func (*Rsa) Encrypt added in v1.0.3

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

Encrypt 加密

func (*Rsa) Sign added in v1.0.3

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

Sign 数据签名

func (*Rsa) Verify added in v1.0.3

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

Verify 数据验签

type ShardMap

type ShardMap interface {
	// Set 存储
	Set(key interface{}, value interface{}) (isCreate bool)
	// Get 获取
	Get(key interface{}) (value interface{}, exists bool)
	// Exists 是否存在
	Exists(key interface{}) (exists bool)
	// Delete 删除
	Delete(keys ...interface{}) (delNum int)
	// Length 长度
	Length() int64
}

ShardMap 分片Map

func NewSharMapWithChannel added in v1.1.0

func NewSharMapWithChannel(size int) (sm ShardMap, ch <-chan shardmap.ChangeEvent)

NewSharMapWithChannel 实例化ShardMap并返回changeChannel

func NewShardMap

func NewShardMap() ShardMap

NewShardMap 实例化ShardMap

type SnowFlake added in v1.0.8

type SnowFlake interface {
	// Id 生成id
	Id() (int64, error)
	// Info 根据id获取信息
	Info(id int64) (timestamp int64, machineId uint8, index int16)
}

SnowFlake 雪花算法接口,1位0,41位毫秒时间戳,8位机器码,14位递增值

func NewSF added in v1.0.8

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

NewSF 实例化雪花算法

func NewSFByIp added in v1.0.8

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

NewSFByIp ip方式实例化雪花算法

func NewSFByMachineFunc added in v1.0.8

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

NewSFByMachineFunc GetMachineId方式实例化雪花算法

type State added in v1.2.17

type State int32

func StateFromSlice added in v1.2.17

func StateFromSlice(list []uint8) (State, error)

func StatusFromValueSlice added in v1.2.17

func StatusFromValueSlice(list []int32) State

func (*State) Add added in v1.2.17

func (s *State) Add(indexList ...uint8) error

func (*State) Has added in v1.2.17

func (s *State) Has(index uint8) bool

func (*State) Intersection added in v1.2.17

func (s *State) Intersection(val State) []uint8

func (*State) Merge added in v1.2.17

func (s *State) Merge(val State)

func (*State) Remove added in v1.2.17

func (s *State) Remove(index uint8)

func (*State) RemoveAll added in v1.2.17

func (s *State) RemoveAll()

func (*State) Slice added in v1.2.17

func (s *State) Slice() []uint8

func (*State) UnionSet added in v1.2.17

func (s *State) UnionSet(val State) []uint8

func (*State) ValueSlice added in v1.2.17

func (s *State) ValueSlice() []int32

type Status added in v1.2.3

type Status struct {
	Code codes.Code  `json:"code"`
	Msg  string      `json:"msg"`
	Flag uint8       `json:"flag"`
	Data interface{} `json:"data"`
}

func StatusOk added in v1.3.2

func StatusOk(data interface{}) *Status

StatusOk 创建携带数据的Status

func StatusWithCode added in v1.2.3

func StatusWithCode(code codes.Code) *Status

StatusWithCode 指定Code获取一个Status

func StatusWithCodeMsg added in v1.3.2

func StatusWithCodeMsg(code codes.Code, msg string) *Status

StatusWithCodeMsg 实例化Status

func StatusWithJsonUnmarshal added in v1.2.3

func StatusWithJsonUnmarshal(data []byte) (*Status, error)

StatusWithJsonUnmarshal 指定json []byte获取一个Status

func (*Status) Close added in v1.2.3

func (s *Status) Close()

Close 释放Status到sync.Pool

func (*Status) ConvertGrpcStatus added in v1.2.3

func (s *Status) ConvertGrpcStatus(details ...proto.Message) (*status.Status, error)

ConvertGrpcStatus 转换为grpc状态码

func (*Status) Error added in v1.2.3

func (s *Status) Error() error

Error 转换为error

func (*Status) Is added in v1.2.3

func (s *Status) Is(code codes.Code) bool

Is 判断是否是指定Code

func (*Status) IsOK added in v1.2.3

func (s *Status) IsOK() bool

IsOK 操作是否OK

func (*Status) JsonMarshal added in v1.2.3

func (s *Status) JsonMarshal() []byte

JsonMarshal _

func (*Status) ToError added in v1.2.19

func (s *Status) ToError() error

func (*Status) WithData added in v1.2.3

func (s *Status) WithData(data interface{}) *Status

WithData 附加自定义Data

func (*Status) WithFlag added in v1.3.4

func (s *Status) WithFlag(flag uint8) *Status

WithFlag 附加flag

func (*Status) WithMsg added in v1.2.3

func (s *Status) WithMsg(msg string) *Status

WithMsg 附加自定义message

Directories

Path Synopsis
core
examples

Jump to

Keyboard shortcuts

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