bloxid

package
v0.22.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

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

View Source
const (
	DefaultEntropySize = 40
)
View Source
const V0Delimiter = "."

Variables

View Source
var (
	ErrInvalidVersion     error = errors.New("invalid bloxid version")
	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 WithShortID

func WithShortID(shortid string) func(o *V0Options)

Types

type GenerateV0Opts

type GenerateV0Opts func(o *V0Options)

type ID

type ID interface {
	// String returns the complete resource ID
	String() string
	// ShortID returns a shortened ID that will be locally unique
	ShortID() string
	// Version returns a serialized representation of the ID version
	// ie. `V0`
	Version() string // V0
	// Type returns entity type ie. `host`
	Type() string
	// Region is optional and returns the cloud region that
	// the resource is found in ie. `us-east-1`
	Region() 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 GenerateV0

func GenerateV0(opts *V0Options, fnOpts ...GenerateV0Opts) (*V0, error)

func NewV0

func NewV0(bloxid string) (*V0, error)

NewV0 parse a string into a typed guid, return an error if the string fails validation.

func (*V0) Region

func (v *V0) Region() string

Region implements ID.Region

func (*V0) ShortID

func (v *V0) ShortID() string

ShortID implements ID.ShortID

func (*V0) String

func (v *V0) String() string

Serialize the typed guid as a string

func (*V0) Type

func (v *V0) Type() string

Type implements ID.Type

func (*V0) Version

func (v *V0) Version() string

Version of the string

type V0Options

type V0Options struct {
	Region     string
	EntityType string
	// contains filtered or unexported fields
}

V0Options required options to create a typed guid

type Version

type Version uint8
const (
	VersionUnknown Version = iota
	Version0       Version = iota
)

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL