Documentation ¶
Overview ¶
Package snowflake provides a simple snowflake ID generator along with interface implementations to make it easy to use with database/sql and encoding/json.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type NullSnowflake ¶ added in v1.0.2
NullSnowflake is a nullable Snowflake
func NewNullSnowflake ¶ added in v1.0.2
func NewNullSnowflake(s Snowflake, valid bool) NullSnowflake
NewNullSnowflake creates a new NullSnowflake
func NullSnowflakeFromPtr ¶ added in v1.0.3
func NullSnowflakeFromPtr(s *Snowflake) NullSnowflake
NullSnowflakeFromPtr creates a new NullSnowflake from a Snowflake pointer
func NullSnowflakeFromStringPtr ¶ added in v1.0.3
func NullSnowflakeFromStringPtr(s *string) NullSnowflake
NullSnowflakeFromStringPtr creates a new NullSnowflake from a string pointer Always returns a NullSnowflake, will be invalid if the string cannot be converted to an int
func (NullSnowflake) MarshalJSON ¶ added in v1.0.2
func (s NullSnowflake) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*NullSnowflake) Scan ¶ added in v1.0.2
func (s *NullSnowflake) Scan(value any) error
Scan implements sql.Scanner interface
func (*NullSnowflake) UnmarshalJSON ¶ added in v1.0.2
func (s *NullSnowflake) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
func (NullSnowflake) Value ¶ added in v1.0.2
func (s NullSnowflake) Value() (driver.Value, error)
Value implements driver.Valuer interface
func (NullSnowflake) ValueOrZero ¶ added in v1.0.2
func (s NullSnowflake) ValueOrZero() Snowflake
ValueOrZero returns the inner value if valid, otherwise zero.
type Snowflake ¶
type Snowflake uint64
Snowflake represents a single Snowflake ID.
func Generate ¶
func Generate() Snowflake
Generate generates a new Snowflake. This function is thread-safe.
Example ¶
package main import ( "fmt" "time" "github.com/Project-Sparrow/snowflake" ) func main() { epoch := time.Date(2020, 1, 1, 1, 0, 0, 0, time.UTC) snowflake.Init(epoch, 1, 1) fmt.Println(snowflake.Generate()) }
Output:
func SnowflakeFromString ¶
SnowflakeFromString attempts to parse a Snowflake from a string.
func (Snowflake) MarshalJSON ¶
MarshalJSON implements json.Marshaler interface
func (*Snowflake) UnmarshalJSON ¶
MarshalJSON implements json.Unmarshaler interface