Documentation
¶
Index ¶
- Constants
- func HostID() int64
- type SUID
- func (s SUID) Description() string
- func (s SUID) GormDataType() string
- func (s SUID) Group() int64
- func (s SUID) Hex() string
- func (s SUID) Host() int64
- func (s SUID) Int() int64
- func (s SUID) MarshalJSON() ([]byte, error)
- func (s *SUID) Scan(value any) error
- func (s SUID) Seq() int64
- func (s SUID) Str(base ...int) string
- func (s SUID) Time() int64
- func (s *SUID) UnmarshalJSON(data []byte) error
- func (s SUID) Value() (driver.Value, error)
- func (s SUID) Verify() bool
Constants ¶
View Source
const ( MAX_HOST int64 = 0x7f // 7 bits MAX_SEQ int64 = 0x7ffff // 19 bits MAX_TIME int64 = 0x3ffffffff // 34 bits MAX_GROUP int64 = 0x7 // 3 bits )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type SUID ¶
type SUID struct {
// contains filtered or unexported fields
}
Snowflake Unique Identifier SUID is a 64-bit integer. The data structure is symbol(1)-group(3)-time(34)-seq(19)-host(7)
- The host_id will read `SUID_HOST_ID` `POD_NAME` `HOSTNAME` from environment, and pick last part ( separator "-" )
- If run in kubenetes, recommend to use StatefulSet to provide a unique host_id.
- Otherwise, you must set `SUID_HOST_ID` manually to provide a unique host_id.
- The max date for SUID will be `2514-05-30 01:53:03 +0000`
- The max number of concurrent transactions is 524288 per second. It will wait for next second automatically
- Recommend to use SUID as primary key for database table to ensure the uniqueness and performance.
- The SUID will keep threaded-safe and safe for concurrent access.
func FromStr ¶ added in v1.2.0
FromStr creates a SUID from a string with the given base. If base is not given, it will use base 10.
func New ¶
New a SUID with the given group. If group is not given, it will use the default group 0. The max group value is 7
func (SUID) GormDataType ¶ added in v1.1.0
GormDataType implements the gorm.DataTypeInterface interface.
func (SUID) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (SUID) Str ¶ added in v1.4.0
Str returns the string representation of the SUID with the given base. If base is not given, it will use base 10.
func (*SUID) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
Click to show internal directories.
Click to hide internal directories.