id

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2017 License: Apache-2.0 Imports: 10 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

This section is empty.

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.

Jump to

Keyboard shortcuts

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