Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type ID
- func (id ID) Build(builder clause.Builder)
- func (id ID) Encode() string
- func (id ID) Expression() clause.Expression
- func (ID) GormDBDataType(db *gorm.DB, field *schema.Field) string
- func (id ID) GormValue(ctx context.Context, db *gorm.DB) clause.Expr
- func (id ID) Int64() int64
- func (id *ID) IsNil() bool
- func (id *ID) IsValid() bool
- func (id *ID) IsZero() bool
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) NodeID(nodeShift, nodeMask uint8) int64
- func (id *ID) Scan(value interface{}) error
- func (id ID) Step(stepMask int64) int64
- func (id ID) String() string
- func (id ID) Time(epoch time.Time) time.Time
- func (id *ID) UnmarshalJSON(data []byte) error
- func (id ID) Value() (driver.Value, error)
- type JSONSyntaxError
- type SnowflakeID
Constants ¶
View Source
const ( Epoch int64 = 1288834974657 DefaultNodeBits uint8 = 10 DefaultStepBits uint8 = 12 EncodeAlphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ123456789" )
常量定义
Variables ¶
Functions ¶
This section is empty.
Types ¶
type ID ¶
type ID int64
ID 雪花ID类型
func (ID) Expression ¶
func (id ID) Expression() clause.Expression
Expression 实现 GORM 的 Expression 接口,让 ID 在查询中自动转换为 int64
func (ID) GormDBDataType ¶
GormDBDataType gorm 方言映射
func (ID) MarshalJSON ¶
func (*ID) UnmarshalJSON ¶
type JSONSyntaxError ¶
type JSONSyntaxError struct {
Original []byte
}
JSON序列化相关
func (JSONSyntaxError) Error ¶
func (e JSONSyntaxError) Error() string
type SnowflakeID ¶
type SnowflakeID struct {
// contains filtered or unexported fields
}
SnowflakeID 雪花ID生成器
func New ¶
func New(nodeID int64, config ...Config) (*SnowflakeID, error)
NewSnowflakeID 创建新的雪花ID生成器
func (*SnowflakeID) MustGenerate ¶
func (s *SnowflakeID) MustGenerate() ID
MustGenerate 生成ID,如果出错会panic(适用于确定不会出错的场景)
Click to show internal directories.
Click to hide internal directories.