Documentation
¶
Index ¶
- Variables
- func Bytes2Data[T any](bytes []byte) (T, error)
- func CreateProductZapLogger(op ...Option) (*zap.Logger, zap.AtomicLevel, error)
- func FileExists(filename string) bool
- func NativelyLittle() bool
- func NewZapWriter(logger *zap.Logger, level zapcore.Level) io.Writer
- func PathExist(path string) bool
- type AtomicInt
- func (a *AtomicInt) Add(delta int)
- func (a *AtomicInt) CompareAndSwap(oldVal, newVal int) bool
- func (a *AtomicInt) CompareAndSwap64(oldVal, newVal int64) bool
- func (a *AtomicInt) Dec() int
- func (a *AtomicInt) Get() int
- func (a *AtomicInt) Get64() int64
- func (a *AtomicInt) Inc() int
- func (a *AtomicInt) Load() int
- func (a *AtomicInt) Reset()
- func (a *AtomicInt) Set(val int)
- func (a *AtomicInt) Set64(val int64)
- func (a *AtomicInt) Store(val int)
- func (a *AtomicInt) String() string
- func (a *AtomicInt) Swap(newVal int) int
- func (a *AtomicInt) Swap64(newVal int64) int64
- type JSONSyntaxError
- type LogConfig
- type Option
- func SetConsoleWriterSyncer(consoleWriter bool) Option
- func SetLogCompress(compress bool) Option
- func SetLogFilename(filename string) Option
- func SetLogLevel(level zapcore.Level) Option
- func SetLogLevelKey(levelKey string) Option
- func SetLogMaxAge(maxAge int) Option
- func SetLogMaxBackups(maxBackups int) Option
- func SetLogMaxSize(maxSize int) Option
- type SnowID
- func ParseBase2(id string) (SnowID, error)
- func ParseBase32(b []byte) (SnowID, error)
- func ParseBase36(id string) (SnowID, error)
- func ParseBase58(b []byte) (SnowID, error)
- func ParseBase64(id string) (SnowID, error)
- func ParseBytes(id []byte) (SnowID, error)
- func ParseInt64(id int64) SnowID
- func ParseIntBytes(id [8]byte) SnowID
- func ParseString(id string) (SnowID, error)
- func (f SnowID) Base2() string
- func (f SnowID) Base32() string
- func (f SnowID) Base36() string
- func (f SnowID) Base58() string
- func (f SnowID) Base64() string
- func (f SnowID) Bytes() []byte
- func (f SnowID) Int64() int64
- func (f SnowID) IntBytes() [8]byte
- func (f SnowID) MarshalJSON() ([]byte, error)
- func (f SnowID) Node() int64
- func (f SnowID) Step() int64
- func (f SnowID) String() string
- func (f SnowID) Time() int64
- func (f *SnowID) UnmarshalJSON(b []byte) error
- type SnowNode
- type ZapWriter
Constants ¶
This section is empty.
Variables ¶
var ( // Epoch is set to the twitter snowflake epoch of Nov 04 2010 01:42:54 UTC in milliseconds // You may customize this to set a different epoch for your application. Epoch int64 = 1288834974657 // NodeBits holds the number of bits to use for SnowNode // Remember, you have a total 22 bits to share between SnowNode/Step NodeBits uint8 = 10 // StepBits holds the number of bits to use for Step // Remember, you have a total 22 bits to share between SnowNode/Step StepBits uint8 = 12 )
var ErrInvalidBase32 = errors.New("invalid base32")
ErrInvalidBase32 is returned by ParseBase32 when given an invalid []byte
var ErrInvalidBase58 = errors.New("invalid base58")
ErrInvalidBase58 is returned by ParseBase58 when given an invalid []byte
Functions ¶
func Bytes2Data ¶
func CreateProductZapLogger ¶
CreateProductZapLogger 创建一个生产级别的 zap 日志记录器。 返回的 zap.AtomicLevel 可用于运行时动态修改日志等级。
func FileExists ¶
func NewZapWriter ¶
NewZapWriter 创建一个新的 io.Writer,输出到 zap.Logger level: 日志级别 (zap.InfoLevel, zap.WarnLevel 等)
Types ¶
type AtomicInt ¶
type AtomicInt struct {
// contains filtered or unexported fields
}
func NewAtomicInt ¶
func NewAtomicInt64 ¶
func (*AtomicInt) CompareAndSwap ¶
func (*AtomicInt) CompareAndSwap64 ¶
type JSONSyntaxError ¶
type JSONSyntaxError struct {
// contains filtered or unexported fields
}
A JSONSyntaxError is returned from UnmarshalJSON if an invalid ID is provided.
func (JSONSyntaxError) Error ¶
func (j JSONSyntaxError) Error() string
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
An Option configures a Logger.
func SetConsoleWriterSyncer ¶
type SnowID ¶
type SnowID int64
An SnowID is a custom type used for a snowflake SnowID. This is used so we can attach methods onto the SnowID.
func ParseBase2 ¶
ParseBase2 converts a Base2 string into a snowflake SnowID
func ParseBase32 ¶
ParseBase32 parses a base32 []byte into a snowflake SnowID NOTE: There are many different base32 implementations so becareful when doing any interoperation.
func ParseBase36 ¶
ParseBase36 converts a Base36 string into a snowflake SnowID
func ParseBase58 ¶
ParseBase58 parses a base58 []byte into a snowflake SnowID
func ParseBase64 ¶
func ParseBytes ¶
func ParseInt64 ¶
ParseInt64 converts an int64 into a snowflake SnowID
func ParseIntBytes ¶
ParseIntBytes converts an array of bytes encoded as big endian integer as a snowflake SnowID
func ParseString ¶
ParseString converts a string into a snowflake SnowID
func (SnowID) Base32 ¶
Base32 uses the z-base-32 character set but encodes and decodes similar to base58, allowing it to create an even smaller result string. NOTE: There are many different base32 implementations so becareful when doing any interoperation.
func (SnowID) IntBytes ¶
IntBytes returns an array of bytes of the snowflake SnowID, encoded as a big endian integer.
func (SnowID) MarshalJSON ¶
MarshalJSON returns a json byte array string of the snowflake SnowID.
func (SnowID) Node ¶
Node SnowNode returns an int64 of the snowflake SnowID node number DEPRECATED: the below function will be removed in a future release.
func (SnowID) Step ¶
Step returns an int64 of the snowflake step (or sequence) number DEPRECATED: the below function will be removed in a future release.
func (SnowID) Time ¶
Time returns an int64 unix timestamp in milliseconds of the snowflake SnowID time DEPRECATED: the below function will be removed in a future release.
func (*SnowID) UnmarshalJSON ¶
UnmarshalJSON converts a json byte array of a snowflake SnowID into an SnowID type.
type SnowNode ¶
type SnowNode struct {
// contains filtered or unexported fields
}
A SnowNode struct holds the basic information needed for a snowflake generator node
func NewSnowNode ¶
NewSnowNode returns a new snowflake node that can be used to generate snowflake IDs