xid

package
v3.1.14 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCharacter = errors.New("invalid character for encoding")
)

Functions

func Encode

func Encode(n ID) string

Base62 Encode

Types

type Config

type Config struct {
	NodeID      int64
	CounterBits uint8
	Salt        int64
}

Config 配置

type Generator

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

func New

func New(cfg *Config) *Generator

新建生成器

func (*Generator) MustGenerate

func (g *Generator) MustGenerate() ID

func (*Generator) Next

func (g *Generator) Next() string

---------------------------- 生成可给用户使用的 8 位 Base62 ID ----------------------------

func (*Generator) NextID

func (g *Generator) NextID() ID

Next 生成 8 位 Base62 ID

type ID

type ID int64

func Decode

func Decode(s string) (ID, error)

Basebase Decode

func ParseString

func ParseString(s string) (ID, error)

ParseString 从字符串解析ID

func (ID) Encode added in v3.1.5

func (id ID) Encode() string

func (ID) GormDBDataType

func (ID) GormDBDataType(db *gorm.DB, field *schema.Field) string

GormDBDataType gorm 方言映射

func (ID) GormValue

func (id ID) GormValue(ctx context.Context, db *gorm.DB) clause.Expr

GormValue 添加 GORM 特定的方法

func (ID) Int64

func (id ID) Int64() int64

func (*ID) IsValid

func (id *ID) IsValid() bool

func (*ID) IsZero

func (id *ID) IsZero() bool

func (ID) MarshalBinary

func (id ID) MarshalBinary() ([]byte, error)

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

func (*ID) Scan

func (id *ID) Scan(value any) error

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalBinary

func (id *ID) UnmarshalBinary(data []byte) error

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

func (ID) Value

func (id ID) Value() (driver.Value, error)

实现 GORM 的序列化接口

type JSONSyntaxError added in v3.1.4

type JSONSyntaxError struct {
	Original []byte
}

JSON序列化相关

func (JSONSyntaxError) Error added in v3.1.4

func (e JSONSyntaxError) Error() string

Jump to

Keyboard shortcuts

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