tind/tind.go

53 lines
1.6 KiB
Go

// Package tind provides a simple random identifier as a byte slice
package tind
// TinD: Because a UUID is too big for a lot of people
// a TinD is a defaults to a 4 byte ID made up of ONLY Alphabetical characters.
// To ensure more randomness, lower case and upper case letters are used
// providing up to 52 differenct characters for use in each single position.
//
// TinD is at it's core a byte slice. It's default alphabet can be replaced with
// whatever unicode characters you want, as the alphabet it uses is just a slice
// of runes
// defaults are just a call to New()
var defaults = New()
// TinD represents a very simple `size` byte unique ID that is generated
// at random. TinD stands for Tiny iDentifier, and is pronouced "tind"
// Each byte can be the value 0 -> len(alphabet) that is used, to ensure
// values can be encoded and decoded reliably. The longer the alphabet
// used, the more randomness can be done.
type TinD struct {
bytes []byte
runes []rune
config *Config
}
// Gen generates a new TinD id using default values
func Gen() TinD {
return defaults.Gen()
}
// String returns the Human Readable form of the TinD
func (t TinD) String() string {
return string(t.runes)
}
// Runes returns the Rune array of the TinD
func (t TinD) Runes() []rune {
return t.runes
}
// Bytes returns the raw bytes of the TinD
func (t TinD) Bytes() []byte {
return t.bytes
}
// Config allows access to the underlying configuration. When used with the
// default TinD (ie. by calling the package level Gen()), allows the user to
// modify the default configuration.
func (t TinD) Config() *Config {
return t.config
}