id

package
v3.2.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

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

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

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

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