Versions in this module Expand all Collapse all v2 v2.0.15 Mar 10, 2024 v2.0.14 Mar 7, 2024 v2.0.12 Mar 7, 2024 v2.0.11 Feb 26, 2024 v2.0.10 Feb 26, 2024 v2.0.9 Jan 25, 2024 Changes in this version + type Chain struct + func NewChain(handlers ...Handler) *Chain + func (c *Chain) Run() + func (c *Chain) RunWithCtx(ctx *Context) + func (c *Chain) Use(handlers ...Handler) type Context + func (c *Context) Event() *Event + func (c *Context) GetUint(key string, defaultVal uint64) (value uint64) + func (c *Context) SetEvent(event *Event) + type Event struct + func (e *Event) Data() any + func (e *Event) Name() string + type EventManager struct + func (em *EventManager) Has(name string) bool + func (em *EventManager) On(name string, handlers ...Handler) + func (em *EventManager) Trigger(name string, data any) v2.0.8 Dec 23, 2023 v2.0.7 Dec 18, 2023 v2.0.6 Dec 13, 2023 v2.0.5 Dec 10, 2023 v2.0.4 Dec 9, 2023 v2.0.3 Dec 9, 2023 v2.0.2 Dec 9, 2023 v2.0.1 Dec 9, 2023 v2.0.0 Dec 9, 2023 Changes in this version + const CodeAborted + const CodeAlreadyExists + const CodeCanceled + const CodeDataLoss + const CodeDeadlineExceeded + const CodeFailedPrecondition + const CodeInternal + const CodeInvalidArgument + const CodeNotFound + const CodeOutRange + const CodePermissionDenied + const CodeResourceExhausted + const CodeUnauthenticated + const CodeUnavailable + const CodeUnimplemented + const CodeUnknown + const EnvDev + const EnvPro + const EnvTest + const ModeError + const ModeMaxTime + const ModeWait + const OK + const ZhCn + var ErrAesDecrypt = errors.New(`aes decrypt error`) + var ErrAlphanumeric = errors.New("alphanumeric must be [a-zA-Z0-9] and not repeat") + var ErrAlphanumericLength = errors.New("alphanumeric length must be [50, 62]") + var ErrDataEmpty = errors.New("data is empty") + var ErrDataFormat = errors.New("invalid data format") + var ErrInvalidPaddingChar = errors.New(`invalid padding char`) + var ErrMachineId = errors.New("illegal machine id") + var ErrMsgMapEmpty = errors.New("msgMap can not empty") + var ErrNoJsonFiles = errors.New("there are no `.json` files in this directory") + var ErrNoServer = errors.New("no server") + var ErrNoYamlFiles = errors.New("there are no `.yml` or `.yaml` files in this directory") + var ErrOutOfRange = errors.New("out of range") + var ErrTimeBack = errors.New("time go back") + func Code2Id(code []byte) (id int64, err error) + func Code6(id int64) (code []byte, err error) + func Code6String(id int64) (code string, err error) + func Code6To8(code6 []byte) (code8 []byte, err error) + func Code8(id int64) (code []byte, err error) + func Code8String(id int64) (code string, err error) + func CodeString2Id(code string) (id int64, err error) + func CodeString6To8(code6 string) (code8 string, err error) + func CreatePkcs1Keys(keyLength int) (privateKey, publicKey string) + func CreatePkcs8Keys(keyLength int) (privateKey, publicKey string) + func MarshalPkcs8PrivateKey(key *rsa.PrivateKey) []byte + func Max6() int64 + func Max8() int64 + type Aes struct + func NewAes(key, iv string) (a *Aes, err error) + func NewAesWithBytes(key, iv []byte) (a *Aes, err error) + func (a *Aes) CbcDecrypt(secretData []byte) (data []byte, err error) + func (a *Aes) CbcEncrypt(plain []byte) (secretData []byte) + type Config struct + Addr string + Env string + Logger logger.Option + Name string + Params JsonParam + PprofAddr string + Ver string + func (c *Config) IsEnv(env string) bool + type Context struct + func AcquireCtx(handlers []Handler) *Context + func (c *Context) Abort() + func (c *Context) Close() + func (c *Context) Deadline() (deadline time.Time, ok bool) + func (c *Context) Done() <-chan struct{} + func (c *Context) Err() error + func (c *Context) Get(key string) (value any, exists bool) + func (c *Context) GetBool(key string) (value bool, exists bool) + func (c *Context) GetInt(key string) (value int, exists bool) + func (c *Context) GetInt64(key string) (value int64, exists bool) + func (c *Context) GetInt8(key string) (value int8, exists bool) + func (c *Context) GetString(key string) (value string, exists bool) + func (c *Context) IsAborted() bool + func (c *Context) Next() + func (c *Context) Set(key string, value any) + func (c *Context) Value(key any) any + type GetMachineId func() (id int64, err error) + func GetMachineIdByEnv(key string) GetMachineId + func GetMachineIdByIp() GetMachineId + type Handler func(ctx *Context) + type HashRing interface + Add func(server kind.CanHash) + Get func(key any) (server kind.CanHash, err error) + Index func(index int) (server kind.CanHash, err error) + Length func() int + Range func(handler func(index int, server kind.CanHash, hitCount uint64) (handled bool)) + Remove func(server kind.CanHash) + Store func(servers ...kind.CanHash) + func NewHashRing(servers ...kind.CanHash) HashRing + type I18n interface + T func(key, language string) (msg string) + func NewI18n(defaultLanguage string, msgMap map[string]map[string]string) (i I18n, err error) + func NewI18nFromJson(defaultLanguage string, dir string) (i I18n, err error) + func NewI18nFromYaml(defaultLanguage string, dir string) (i I18n, err error) + type IdCode struct + func NewIdCode(alphanumericSet []byte, salt6, salt8 int64) (*IdCode, error) + func (ic *IdCode) Code2Id(code []byte) (id int64, err error) + func (ic *IdCode) Code6(id int64) (code []byte, err error) + func (ic *IdCode) Code6String(id int64) (code string, err error) + func (ic *IdCode) Code6To8(code6 []byte) (code8 []byte, err error) + func (ic *IdCode) Code8(id int64) (code []byte, err error) + func (ic *IdCode) Code8String(id int64) (code string, err error) + func (ic *IdCode) CodeString2Id(code string) (id int64, err error) + func (ic *IdCode) CodeString6To8(code6 string) (code8 string, err error) + func (ic *IdCode) Max6() int64 + func (ic *IdCode) Max8() int64 + type JsonParam map[string]any + func UnmarshalJsonParam(data []byte) (JsonParam, error) + func (jp JsonParam) Exists(key string) bool + func (jp JsonParam) Float64(key string) float64 + func (jp JsonParam) Int(key string) int + func (jp JsonParam) Int64(key string) int64 + func (jp JsonParam) Int64Slice(key string) []int64 + func (jp JsonParam) IntSlice(key string) []int + func (jp JsonParam) JsonMarshal() []byte + func (jp JsonParam) String(key string) string + func (jp JsonParam) StringSlice(key string) []string + func (jp JsonParam) Uint32Slice(key string) []uint32 + type Mysql struct + Options MysqlOption + func NewMysql(opt MysqlOption) (mysql *Mysql, err error) + type MysqlOption struct + CharSet string + ConnMaxIdleTimeSecond int64 + ConnMaxLifetimeSecond int64 + DbName string + Host string + MaxIdleConns int + MaxOpenConns int + Password string + Port uint32 + UserName string + func DefaultMysqlOption() MysqlOption + func MysqlOptionWithJson(conf string) (opt MysqlOption, err error) + func MysqlOptionWithYaml(conf string) (opt MysqlOption, err error) + func (mo *MysqlOption) Dsn() string + type Node struct + type NodeList []Node + func (n NodeList) Len() int + func (n NodeList) Less(i, j int) bool + func (n NodeList) Swap(i, j int) + type Package struct + Id uint16 + Name string + Param JsonParam + func (p *Package) Pack() []byte + func (p *Package) Unpack(data []byte) error + type Rsa struct + func NewRsa(publicKey, privateKey string) (r *Rsa, err error) + func NewRsaBytes(public, private []byte) (r *Rsa, err error) + func NewRsaWithPkcs1(publicKey, privateKey string) (r *Rsa, err error) + func NewRsaWithPkcs1Bytes(public, private []byte) (r *Rsa, err error) + func NewRsaWithPkcs8(publicKey, privateKey string) (r *Rsa, err error) + func NewRsaWithPkcs8Bytes(public, private []byte) (r *Rsa, err error) + func (r *Rsa) Decrypt(secretData []byte) ([]byte, error) + func (r *Rsa) Encrypt(data []byte) ([]byte, error) + func (r *Rsa) Sign(data []byte, algorithmSign crypto.Hash) ([]byte, error) + func (r *Rsa) Verify(data []byte, sign []byte, algorithmSign crypto.Hash) bool + type SnowFlake interface + Id func() (int64, error) + Info func(id int64) (timestamp int64, machineId uint8, index int16) + func NewSF(mode uint8, id uint8, beginSeconds int64) (sfl SnowFlake, err error) + func NewSFByIp(mode uint8, beginSeconds int64) (sfl SnowFlake, err error) + func NewSFByMachineFunc(mode uint8, machindFunc GetMachineId, beginSeconds int64) (sfl SnowFlake, err error) + type Status struct + Code codes.Code + Data any + Flag uint8 + Msg string + func StatusOk(data any) *Status + func StatusWithCode(code codes.Code) *Status + func StatusWithCodeMsg(code codes.Code, msg string) *Status + func StatusWithJsonUnmarshal(data []byte) (*Status, error) + func (s *Status) Close() + func (s *Status) ConvertGrpcStatus(details ...proto.Message) (*status.Status, error) + func (s *Status) Error() string + func (s *Status) IsCode(code codes.Code) bool + func (s *Status) IsOK() bool + func (s *Status) JsonMarshal() []byte + func (s *Status) ToError() error + func (s *Status) WithData(data any) *Status + func (s *Status) WithFlag(flag uint8) *Status + func (s *Status) WithMsg(msg string) *Status