Goflake is a disributed uuid generator. By default it uses SnowFlake configuration.
Goflake comes with both grpc
and http
servers so you can use it in your own applications without any additional dependencies (including TLS).
See announcing snowflake by Twitter.
go install github.com/Avielyo10/goflake@latest
Goflake will try to read configuration from /etc/goflake/config.yaml
or $CWD/config.yaml
if it exists, else default will apply. You can also specify configuration from environment variables to override configuration from file.
For example:
env "SERVER.TYPE=rest" DATACENTER_ID=1 MACHINE_ID=2 go run .
-
log_level
: either debug, info, warn, error, fatal -
env
: either development, production -
datacenter_id
: can be 0 - 2 ^ flake.bits_len.datacenter_id - 1 -
machine_id
: can be 0 - 2 ^ flake.bits_len.machine_id - 1 -
flake configuration
bits_len
: bits length of flake id, needs to sum to 63 (1 bit for sign)datacenter_id
: uint64, default 5machine_id
: uint64, default 5sequence
: uint64, default 12time
: uint64, default 41
epoch
: epoch of flake id, default is Thu Jul 28 2022 18:57:35 UTCtick_ms
: tick interval in milliseconds to set sequence to 0, default is 1ms
-
server configuration
host
: server hostport
: server porttls configuration
cert_path
: path to certificate filekey_path
: path to key file
type
: either grpc, rest
See example config