tind/tind.go

46 lines
1.3 KiB
Go
Raw Normal View History

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 NewConfig()
var defaults = NewTinDConfig()
// 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
}