uid

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2022 License: BSD-3-Clause Imports: 10 Imported by: 15

README

go-uid

Go package providing a common interface for generating unique identifiers

Documentation

Documentation is incomplete at this time.

Important

Although the interfaces in this package are nearly stable in advance of a v1.0.0 release they may still change.

See also

Documentation

Overview

Package uid provides a common interface for generating unique identifiers

Index

Constants

View Source
const NULL_SCHEME string = "null"

NULL_SCHEME is the URI scheme used to identify NullProvider instances.

View Source
const RANDOM_SCHEME string = "random"
View Source
const STRING_SCHEME string = "string"
View Source
const YMD_SCHEME string = "ymd"

Variables

This section is empty.

Functions

func AsInt64

func AsInt64(u UID) (int64, bool)

func RegisterProvider

func RegisterProvider(ctx context.Context, scheme string, init_func ProviderInitializationFunc) error

RegisterProvider registers 'scheme' as a key pointing to 'init_func' in an internal lookup table used to create new `Provider` instances by the `NewProvider` method.

func Schemes

func Schemes() []string

Schemes returns the list of schemes that have been registered.

Types

type Int64UID added in v0.4.0

type Int64UID struct {
	UID
	// contains filtered or unexported fields
}

func (*Int64UID) String added in v0.4.0

func (u *Int64UID) String() string

func (*Int64UID) Value added in v0.4.0

func (u *Int64UID) Value() any

type MultiUID added in v0.4.0

type MultiUID struct {
	UID
	// contains filtered or unexported fields
}

func (*MultiUID) String added in v0.4.0

func (r *MultiUID) String() string

func (*MultiUID) Value added in v0.4.0

func (r *MultiUID) Value() any

type NullProvider

type NullProvider struct {
	Provider
}

type NullProvider implements the Provider interface to return empty (null) identifiers.

func (*NullProvider) SetLogger added in v0.2.0

func (n *NullProvider) SetLogger(ctx context.Context, logger *log.Logger) error

func (*NullProvider) UID

func (n *NullProvider) UID(ctx context.Context, args ...interface{}) (UID, error)

type NullUID

type NullUID struct {
	UID
}

type NullProvider implements the UID interface to return empty (null) identifiers.

func (*NullUID) String

func (n *NullUID) String() string

func (*NullUID) Value

func (n *NullUID) Value() any

type Provider

type Provider interface {
	UID(context.Context, ...interface{}) (UID, error)
	SetLogger(context.Context, *log.Logger) error
}

func NewNullProvider

func NewNullProvider(ctx context.Context, uri string) (Provider, error)

NewNullProvider

null://

func NewProvider

func NewProvider(ctx context.Context, uri string) (Provider, error)

NewProvider returns a new `Provider` instance configured by 'uri'. The value of 'uri' is parsed as a `url.URL` and its scheme is used as the key for a corresponding `ProviderInitializationFunc` function used to instantiate the new `Provider`. It is assumed that the scheme (and initialization function) have been registered by the `RegisterProvider` method.

func NewRandomProvider

func NewRandomProvider(ctx context.Context, uri string) (Provider, error)

func NewStringProvider

func NewStringProvider(ctx context.Context, uri string) (Provider, error)

func NewYMDProvider

func NewYMDProvider(ctx context.Context, uri string) (Provider, error)

type ProviderInitializationFunc

type ProviderInitializationFunc func(ctx context.Context, uri string) (Provider, error)

ProviderInitializationFunc is a function defined by individual provider package and used to create an instance of that provider

type RandomProvider

type RandomProvider struct {
	Provider
}

func (*RandomProvider) SetLogger added in v0.2.0

func (pr *RandomProvider) SetLogger(ctx context.Context, logger *log.Logger) error

func (*RandomProvider) UID

func (pr *RandomProvider) UID(ctx context.Context, args ...interface{}) (UID, error)

type StringProvider

type StringProvider struct {
	Provider
	// contains filtered or unexported fields
}

func (*StringProvider) SetLogger added in v0.2.0

func (pr *StringProvider) SetLogger(ctx context.Context, logger *log.Logger) error

func (*StringProvider) UID

func (pr *StringProvider) UID(ctx context.Context, args ...interface{}) (UID, error)

type StringUID

type StringUID struct {
	UID
	// contains filtered or unexported fields
}

func (*StringUID) String

func (u *StringUID) String() string

func (*StringUID) Value

func (u *StringUID) Value() any

type UID

type UID interface {
	Value() any
	String() string
}

func NewInt64UID added in v0.4.0

func NewInt64UID(ctx context.Context, i int64) (UID, error)

func NewMultiUID added in v0.4.0

func NewMultiUID(ctx context.Context, uids ...UID) UID

func NewNullUID

func NewNullUID(ctx context.Context) (UID, error)

func NewStringUID

func NewStringUID(ctx context.Context, s string) (UID, error)

func NewYMDUID

func NewYMDUID(ctx context.Context, date time.Time) (UID, error)

type YMDProvider

type YMDProvider struct {
	Provider
}

func (*YMDProvider) SetLogger added in v0.2.0

func (pr *YMDProvider) SetLogger(ctx context.Context, logger *log.Logger) error

func (*YMDProvider) UID

func (pr *YMDProvider) UID(ctx context.Context, args ...interface{}) (UID, error)

type YMDUID

type YMDUID struct {
	UID
	// contains filtered or unexported fields
}

func (*YMDUID) String

func (u *YMDUID) String() string

func (*YMDUID) Value

func (u *YMDUID) Value() any

Directories

Path Synopsis
cmd
uid

Jump to

Keyboard shortcuts

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