diff --git a/README.md b/README.md index 3a9a1aa..fc859b8 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ As a result, Sonyflake has the following advantages and disadvantages: - The lifetime (174 years) is longer than that of Snowflake (69 years) - It can work in more distributed machines (2^16) than Snowflake (2^10) -- It can generate 2^8 IDs per 10 msec at most in a single machine/thread (slower than Snowflake) +- It can generate 2^8 IDs per 10 msec at most in a single machine/thread (fewer than Snowflake) However, if you want more generation rate in a single host, you can easily run multiple Sonyflake ID generators concurrently using goroutines. @@ -50,16 +50,15 @@ type Settings struct { ``` - StartTime is the time since which the Sonyflake time is defined as the elapsed time. - If StartTime is 0, the start time of the Sonyflake is set to "2014-09-01 00:00:00 +0000 UTC". - If StartTime is ahead of the current time, Sonyflake is not created. + If StartTime is 0, the start time of the Sonyflake instance is set to "2025-01-01 00:00:00 +0000 UTC". + StartTime must be before the current time. -- MachineID returns the unique ID of the Sonyflake instance. - If MachineID returns an error, Sonyflake is not created. - If MachineID is nil, default MachineID is used. - Default MachineID returns the lower 16 bits of the private IP address. +- MachineID returns the unique ID of a Sonyflake instance. + If MachineID returns an error, the instance will not be created. + If MachineID is nil, the default MachineID is used, which returns the lower 16 bits of the private IP address. -- CheckMachineID validates the uniqueness of the machine ID. - If CheckMachineID returns false, Sonyflake is not created. +- CheckMachineID validates the uniqueness of a machine ID. + If CheckMachineID returns false, the instance will not be created. If CheckMachineID is nil, no validation is done. In order to get a new unique ID, you just have to call the method NextID. @@ -74,7 +73,7 @@ But after the Sonyflake time is over the limit, NextID returns an error. AWS VPC and Docker ------------------ -The [awsutil](https://github.com/sony/sonyflake/blob/master/awsutil) package provides +The [awsutil](https://github.com/sony/sonyflake/blob/master/v2/awsutil) package provides the function AmazonEC2MachineID that returns the lower 16-bit private IP address of the Amazon EC2 instance. It also works correctly on Docker by retrieving [instance metadata](http://docs.aws.amazon.com/en_us/AWSEC2/latest/UserGuide/ec2-instance-metadata.html). @@ -85,7 +84,7 @@ So if each EC2 instance has a unique private IP address in AWS VPC, the lower 16 bits of the address is also unique. In this common case, you can use AmazonEC2MachineID as Settings.MachineID. -See [example](https://github.com/sony/sonyflake/blob/master/example) that runs Sonyflake on AWS Elastic Beanstalk. +See [example](https://github.com/sony/sonyflake/blob/master/v2/example) that runs Sonyflake on AWS Elastic Beanstalk. License ------- diff --git a/v2/sonyflake.go b/v2/sonyflake.go index f829403..1906c2a 100644 --- a/v2/sonyflake.go +++ b/v2/sonyflake.go @@ -26,16 +26,15 @@ const ( // Settings configures Sonyflake: // // StartTime is the time since which the Sonyflake time is defined as the elapsed time. -// If StartTime is 0, the start time of the Sonyflake is set to "2014-09-01 00:00:00 +0000 UTC". -// If StartTime is ahead of the current time, Sonyflake is not created. +// If StartTime is 0, the start time of the Sonyflake instance is set to "2025-01-01 00:00:00 +0000 UTC". +// StartTime must be before the current time. // -// MachineID returns the unique ID of the Sonyflake instance. -// If MachineID returns an error, Sonyflake is not created. -// If MachineID is nil, default MachineID is used. -// Default MachineID returns the lower 16 bits of the private IP address. +// MachineID returns the unique ID of a Sonyflake instance. +// If MachineID returns an error, the instance will not be created. +// If MachineID is nil, the default MachineID is used, which returns the lower 16 bits of the private IP address. // -// CheckMachineID validates the uniqueness of the machine ID. -// If CheckMachineID returns false, Sonyflake is not created. +// CheckMachineID validates the uniqueness of a machine ID. +// If CheckMachineID returns false, the instance will not be created. // If CheckMachineID is nil, no validation is done. type Settings struct { StartTime time.Time @@ -98,8 +97,6 @@ func New(st Settings) (*Sonyflake, error) { return sf, nil } -// NextID generates a next unique ID. -// After the Sonyflake time overflows, NextID returns an error. // NextID generates a next unique ID as int64. // After the Sonyflake time overflows, NextID returns an error. func (sf *Sonyflake) NextID() (int64, error) {