mirror of
https://github.com/sony/sonyflake.git
synced 2026-11-22 08:06:28 +00:00
Remove NewSonyflake
This commit is contained in:
1 parent
c847588763
commit
313db86c15
3 files changed
+9
-14
No files matched your search
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/sony/sonyflake/v2"
|
"github.com/sony/sonyflake/v2"
|
||||||
@@ -13,7 +14,11 @@ var sf *sonyflake.Sonyflake
|
|||||||
func init() {
|
func init() {
|
||||||
var st sonyflake.Settings
|
var st sonyflake.Settings
|
||||||
st.MachineID = awsutil.AmazonEC2MachineID
|
st.MachineID = awsutil.AmazonEC2MachineID
|
||||||
sf = sonyflake.NewSonyflake(st)
|
var err error
|
||||||
|
sf, err = sonyflake.New(st)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
if sf == nil {
|
if sf == nil {
|
||||||
panic("sonyflake not created")
|
panic("sonyflake not created")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,16 +98,6 @@ func New(st Settings) (*Sonyflake, error) {
|
|||||||
return sf, nil
|
return sf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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.
|
|
||||||
// - Settings.MachineID returns an error.
|
|
||||||
// - Settings.CheckMachineID returns false.
|
|
||||||
func NewSonyflake(st Settings) *Sonyflake {
|
|
||||||
sf, _ := New(st)
|
|
||||||
return sf
|
|
||||||
}
|
|
||||||
|
|
||||||
// NextID generates a next unique ID.
|
// NextID generates a next unique ID.
|
||||||
// After the Sonyflake time overflows, NextID returns an error.
|
// After the Sonyflake time overflows, NextID returns an error.
|
||||||
// NextID generates a next unique ID as int64.
|
// NextID generates a next unique ID as int64.
|
||||||
|
|||||||
@@ -21,9 +21,9 @@ func init() {
|
|||||||
var st Settings
|
var st Settings
|
||||||
st.StartTime = time.Now()
|
st.StartTime = time.Now()
|
||||||
|
|
||||||
sf = NewSonyflake(st)
|
sf, err := New(st)
|
||||||
if sf == nil {
|
if err != nil {
|
||||||
panic("sonyflake not created")
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime = toSonyflakeTime(st.StartTime)
|
startTime = toSonyflakeTime(st.StartTime)
|
||||||
|
|||||||
Reference in new issue
Block a user