Documentation ¶
Overview ¶
Bloxid implements typed guids for identifying resource objects globally in the system. Resources are not specific to services/applications but must contain an entity type.
Typed guids have the advantage of being globally unique, easily readable, and strongly typed for authorization and logging. The trailing characters provide sufficient entropy to make each resource universally unique.
Bloxid package provides methods for generating and parsing versioned typed guids.
Index ¶
- Constants
- Variables
- func WithEntityDomain(domain string) func(o *V0Options)
- func WithEntityType(eType string) func(o *V0Options)
- func WithExtrinsicID(eid string) func(o *V0Options)
- func WithHashIDInt64(id int64) func(o *V0Options)
- func WithHashIDSalt(salt string) func(o *V0Options)
- func WithRealm(realm string) func(o *V0Options)
- type EncodeDecodeOpts
- type GenerateV0Opts
- type ID
- type V0
- type V0Options
- type Version
Constants ¶
const ( DefaultUniqueIDDecodedCharSize = 40 // must be even number and multiple of 40 bits DefaultUniqueIDEncodedCharSize = DefaultUniqueIDDecodedCharSize * 5 / 8 // must be divisible by 8 without remainder DefaultUniqueIDByteSize = DefaultUniqueIDDecodedCharSize / 2 // must be divisible by 2 without remainder DefaultEntropySize = DefaultUniqueIDDecodedCharSize // deprecated but kept for back compat )
const ( UniqueIDEncodedMinCharSize = 16 VersionUnknown Version = iota Version0 Version = iota IDSchemeRandom = "random" )
const (
IDSchemeExtrinsic = "extrinsic"
)
const (
IDSchemeHashID = "hashid"
)
const (
V0Delimiter = "."
)
Variables ¶
var ( ErrEmptyExtrinsicID = errors.New("empty extrinsic id") ErrInvalidExtrinsicID = errors.New("invalid extrinsic id") )
var ( ErrInvalidSalt = errors.New("invalid salt") ErrInvalidID = errors.New("invalid id") )
var ( ErrInvalidVersion error = errors.New("invalid bloxid version") ErrInvalidEntityDomain error = errors.New("entity domain must be non-empty") ErrInvalidEntityType error = errors.New("entity type must be non-empty") ErrInvalidUniqueIDLen error = errors.New("unique ID did not meet minimum length requirements") ErrIDEmpty error = errors.New("empty bloxid") ErrV0Parts error = errors.New("invalid number of parts found") )
Functions ¶
func WithEntityDomain ¶ added in v0.25.2
func WithEntityType ¶ added in v0.25.2
func WithExtrinsicID ¶ added in v0.25.2
WithExtrinsicID supplies a locally unique ID that is not randomly generated
func WithHashIDInt64 ¶ added in v0.25.2
func WithHashIDSalt ¶ added in v0.25.2
Types ¶
type EncodeDecodeOpts ¶ added in v0.25.2
type EncodeDecodeOpts func(o *V0Options)
type GenerateV0Opts ¶
type GenerateV0Opts func(o *V0Options)
type ID ¶
type ID interface { // String returns the complete resource ID String() string // Version returns a serialized representation of the ID version // ie. `V0` Version() string // V0 // Domain returns entity domain ie. `infra` Domain() string // Type returns entity type ie. `host` Type() string // Realm is optional and returns the cloud realm that // the resource is found in ie. `us-com-1`, `eu-com-1`, ... Realm() string // EncodedID returns the unique id in encoded format EncodedID() string // DecodedID returns the unique id in decoded format DecodedID() string // Return the id scheme Scheme() string }
ID implements the interface for parsing a resource identifier
type V0 ¶
type V0 struct {
// contains filtered or unexported fields
}
V0 represents a typed guid
func NewV0 ¶
func NewV0(bloxid string, fnOpts ...EncodeDecodeOpts) (*V0, error)
NewV0 parse a string into a typed guid, return an error if the string fails validation.
func (*V0) HashIDInt64 ¶ added in v0.25.2
HashIDInt64 implements ID.hashIDInt64