id

package module
v0.0.0-...-83b0421 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2016 License: BSD-3-Clause Imports: 3 Imported by: 24

README

maturity build status code coverage GoDoc

id

The id package implements a service to generate identifiers.

Documentation

Overview

Package id implements Service to provide simple ID generation using pseudo random strings.

Index

Constants

View Source
const (
	// Hex128 creates a new hexa decimal encoded, pseudo random, 128 bit hash.
	Hex128 int = 16
	// Hex512 creates a new hexa decimal encoded, pseudo random, 512 bit hash.
	Hex512 int = 64
	// Hex1024 creates a new hexa decimal encoded, pseudo random, 1024 bit hash.
	Hex1024 int = 128
	// Hex2048 creates a new hexa decimal encoded, pseudo random, 2048 bit hash.
	Hex2048 int = 256
	// Hex4096 creates a new hexa decimal encoded, pseudo random, 4096 bit hash.
	Hex4096 int = 512
)

Variables

This section is empty.

Functions

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

Types

type Service

type Service interface {
	// New tries to create a new object ID using the configured ID type. The
	// returned error might be caused by timeouts reached during the ID creation.
	New() (string, error)
	// WithType tries to create a new object ID using the given ID type. The
	// returned error might be caused by timeouts reached during the ID creation.
	WithType(idType int) (string, error)
}

Service provides pseudo random hash generation used for ID assignment.

func NewService

func NewService(config ServiceConfig) (Service, error)

NewService creates a new configured ID service.

type ServiceConfig

type ServiceConfig struct {

	// RandomService represents a factory returning random numbers.
	RandomService random.Service

	// HashChars represents the characters used to create hashes.
	HashChars string
	// Length defines the ID bit size.
	Length int
}

ServiceConfig represents the configuration used to create a new ID service.

func DefaultServiceConfig

func DefaultServiceConfig() ServiceConfig

DefaultServiceConfig provides a default configuration to create a new ID service by best effort.

Jump to

Keyboard shortcuts

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