Documentation
¶
Index ¶
- Constants
- func NewOrderedID() uint64
- func NewOrderedIDGenerator(initial uint64) func() uint64
- func NewRandomIDGenerator(randSource *rand.Rand) *randomIDGenerator
- type ID
- func (t ID) Base32() string
- func (t ID) Base58() string
- func (t ID) Base62() string
- func (t ID) Base64() string
- func (t ID) Bytes() []byte
- func (t ID) Hex() string
- func (t ID) IsValid() bool
- func (t ID) MarshalJSON() ([]byte, error)
- func (t ID) String() string
- func (t ID) UnmarshalJSON(data []byte) error
- type JSONSyntaxError
- type Snowflake
Constants ¶
View Source
const ( // 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 Snowflake // Remember, you have a total 22 bits to share between Snowflake/Step NodeBits uint8 = 10 // StepBits holds the number of bits to use for Step // Remember, you have a total 22 bits to share between Snowflake/Step StepBits uint8 = 12 )
Variables ¶
This section is empty.
Functions ¶
func NewOrderedIDGenerator ¶ added in v1.7.13
func NewRandomIDGenerator ¶ added in v1.7.13
Types ¶
type ID ¶ added in v1.7.13
type ID []byte
func NewRandomID ¶
func NewRandomID() ID
func (ID) IsValid ¶ added in v1.7.13
IsValid checks whether the trace TraceID is valid. A valid trace ID does not consist of zeros only.
func (ID) MarshalJSON ¶ added in v1.7.13
MarshalJSON implements a custom marshal function to encode ID as a hex string.
func (ID) UnmarshalJSON ¶ added in v1.7.13
type JSONSyntaxError ¶ added in v1.7.14
type JSONSyntaxError struct {
// contains filtered or unexported fields
}
A JSONSyntaxError is returned from UnmarshalJSON if an invalid ID is provided.
func (JSONSyntaxError) Error ¶ added in v1.7.14
func (j JSONSyntaxError) Error() string
type Snowflake ¶ added in v1.7.14
type Snowflake struct {
// contains filtered or unexported fields
}
A Snowflake struct holds the basic information needed for a snowflake generator node
func NewSnowflake ¶ added in v1.7.14
NewSnowflake returns a new snowflake node that can be used to generate snowflake IDs
Click to show internal directories.
Click to hide internal directories.