id

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2017 License: Apache-2.0 Imports: 11 Imported by: 149

Documentation

Overview

Package id provides types and functions for generation of identifiers.

Index

Constants

View Source
const Size = 20

Size is the size of an ID.

Variables

This section is empty.

Functions

func PutRemapper added in v0.9.6

func PutRemapper(ctx context.Context, d Remapper) context.Context

PutRemapper amends a Context by attaching a Remapper reference to it.

Types

type ID

type ID [Size]byte

ID is a codeable unique identifier.

func Hash

func Hash(f func(w io.Writer) error) (ID, error)

Hash creates a new ID by calling f and hashing all data written to w.

func OfBytes

func OfBytes(data ...[]byte) ID

OfBytes calculates the ID for the supplied data using the Hash function.

func OfString

func OfString(strings ...string) ID

OfString calculates the ID for the supplied strings using the Hash function.

func Parse

func Parse(s string) (ID, error)

Parse parses lowercase string s as a 20 byte hex-encoded ID.

func Unique

func Unique() ID

Unique returns a unique identifier by hashing the current time and machine hostname.

func (ID) Format

func (id ID) Format(f fmt.State, c rune)

func (ID) IsValid

func (id ID) IsValid() bool

IsValid returns true if the id is not the default value.

func (ID) MarshalJSON

func (i ID) MarshalJSON() ([]byte, error)

MarshalJSON encodes the ID as a JSON string.

func (*ID) Parse

func (id *ID) Parse(s string) error

Parse parses lowercase string s as a 20 byte hex-encoded ID, or copies s to the ID if it is 20 bytes long.

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalJSON

func (i *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a JSON string as an ID.

type Remapper added in v0.9.6

type Remapper interface {
	RemapIndex(ctx context.Context, index int64) (ID, error)
	RemapID(ctx context.Context, id ID) (int64, error)
}

Remapper is an interface which allows remapping between ID to int64. One such remapper can be stored in the current Context. This is used to handle resource when converting to/from proto. It needs to live here to break go package dependency cycles.

func GetRemapper added in v0.9.6

func GetRemapper(ctx context.Context) Remapper

GetRemapper returns the Remapper attached to the given context.

Jump to

Keyboard shortcuts

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