Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions sonyflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ func New(st Settings) (*Sonyflake, error) {
return sf, nil
}

// Default creates and returns a new Sonyflake instance using the default configuration.
//
// It is equivalent to calling:
//
// New(Settings{})
func Default() (*Sonyflake, error) {
return New(Settings{})
}

// NewSonyflake returns a new Sonyflake configured with the given Settings.
// NewSonyflake returns nil in the following cases:
// - Settings.StartTime is ahead of the current time.
Expand All @@ -109,6 +118,15 @@ func NewSonyflake(st Settings) *Sonyflake {
return sf
}

// DefaultSonyflake creates and returns a new Sonyflake instance using the default Settings.
//
// It is equivalent to calling:
//
// NewSonyflake(Settings{})
func DefaultSonyflake() *Sonyflake {
return NewSonyflake(Settings{})
}

// NextID generates a next unique ID.
// After the Sonyflake time overflows, NextID returns an error.
func (sf *Sonyflake) NextID() (uint64, error) {
Expand Down
9 changes: 9 additions & 0 deletions v2/sonyflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,15 @@ func New(st Settings) (*Sonyflake, error) {
return sf, nil
}

// Default creates and returns a new Sonyflake instance using the default configuration.
//
// It is equivalent to calling:
//
// New(Settings{})
func Default() (*Sonyflake, error) {
return New(Settings{})
}

// NextID generates a next unique ID as int64.
// After the Sonyflake time overflows, NextID returns an error.
func (sf *Sonyflake) NextID() (int64, error) {
Expand Down