Documentation ¶
Index ¶
Constants ¶
const ( // Length of the timestamp section. TimestampLen uint8 = 42 // Length of the Server ID section. ServerIdLen uint8 = 11 // Length of the sequence section. SequenceLen uint8 = 11 // Maximum value for the sequence section. MaxSequence uint16 = 1<<SequenceLen - 1 // Maximum value for the Server ID section. MaxServerId uint16 = 1<<ServerIdLen - 1 // Maximum value for the timestamp section. MaxTimestamp uint64 = 1<<TimestampLen - 1 )
Variables ¶
var ErrEmptyEnvVar = errors.New("getenv: Specified environment variable is empty or undefined")
Functions ¶
func GetEpoch ¶
func GetEpoch() uint64
The epoch used by Snowball is entirely configurable via the SNOWBALL_EPOCH_MS system environment variable. This makes using Snowball in containerized deployments straightforward - just supply the expected environment variable and Snowball will take it from there.
If the epoch is not provided, Snowball defaults to the epoch used by the original Snowflake algorithm.
func GetServerId ¶
func GetServerId() uint64
The server ID used by Snowball is entirely configurable via the SNOWBALL_NODE_ID system environment variable. This makes using Snowball in containerized deployments straightforward - just supply the expected environment variable and Snowball will take it from there.
If the ID is not provided, Snowball defaults to 0.
func GetServerIdFromIPAddress ¶
func GetServerIdFromIPAddress() uint64
Alternatively, the server ID used by Snowball can be based on the machine or pod IP address, via the SERVER_IP_ADDRESS system environment variable. This can be leveraged for containerized deployments that are expected to scale, and providing multiple unique server IDs is more difficult.
func GetenvBoolean ¶
func GetenvInteger ¶
Types ¶
type SnowballID ¶
type SnowballID uint64
Basic type to represent Snowball IDs, e.g., for encoding methods
func FromBase32 ¶
func FromBase32(sid string) (SnowballID, error)
Converts a base32 string into a Snowball ID. Assumes the string is formatted using standard Base32.
func FromBase62 ¶
func FromBase62(sid string) (SnowballID, error)
Converts a base62 string into a Snowball ID.
func FromBase64 ¶
func FromBase64(sid string) (SnowballID, error)
Converts a base64 string into a Snowball ID. Assumes the string is formatted using the URL variant of Base64.
func FromBinary ¶
func FromBinary(sid string) (SnowballID, error)
Converts a binary string into a Snowball ID.
func FromHex ¶
func FromHex(sid string) (SnowballID, error)
Converts a hexidecimal string into a Snowball ID.
func (SnowballID) ToBase32 ¶
func (id SnowballID) ToBase32() string
Formats the Snowball ID into a base32 encoded string, using the standard encoding for Base32.
func (SnowballID) ToBase62 ¶
func (id SnowballID) ToBase62() string
Formats the Snowball ID into a base62 encoded string.
func (SnowballID) ToBase64 ¶
func (id SnowballID) ToBase64() string
Formats the Snowball ID into a base64 encoded string, using the URL encoding for Base64.
func (SnowballID) ToBinary ¶
func (id SnowballID) ToBinary() string
Formats the Snowball ID into a binary string.
func (SnowballID) ToHex ¶
func (id SnowballID) ToHex() string
Formats the Snowball ID into a hexidecimal string.
type SnowballNode ¶
type SnowballNode struct {
// contains filtered or unexported fields
}
Contains basic information used to generate Snowball IDs
func InitNode ¶
func InitNode(useIp bool) (*SnowballNode, error)
Creates and returns a new node object for generating Snowball IDs
func (*SnowballNode) GenerateID ¶
func (node *SnowballNode) GenerateID() SnowballID
Creates and returns a new, unique Snowball ID.