Documentation
¶
Overview ¶
Package indigo generates a distributed unique ID generator of using Sonyflake and encoded by Base58.
More information: https://github.com/osamingo/indigo/blob/master/README.md
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckMachineID ¶ added in v1.0.1
CheckMachineID is optional function for indigo.Generator.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
A Generator has sonyflake and encoder.
func (*Generator) NextID ¶
NextID generates a next unique ID.
Example ¶
package main import ( "fmt" "time" "github.com/osamingo/indigo" ) func main() { //nolint: nosnakecase const machineID = 65535 g := indigo.New( nil, indigo.StartTime(time.Now()), indigo.MachineID(func() (uint16, error) { return machineID, nil }), ) id, err := g.NextID() if err != nil { panic(err) } fmt.Println(id) m, err := g.Decompose(id) if err != nil { panic(err) } fmt.Println(m["machine-id"]) }
Output: 2VKmG 65535
Click to show internal directories.
Click to hide internal directories.