ident

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ident contains utilities for representing arbitrary identifiers.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyID = errors.New("ID is empty")

ErrEmptyID indicates an attempt was made to use an uninitialized ID value.

View Source
var ErrIDNotEmpty = errors.New("can not replace existing ID")

ErrIDNotEmpty indicates an attempt was made to overwrite an existing ID value.

Functions

func Format

func Format(id string) string

Format returns a compact rendering of ID for use in log messages and other human-readable strings. It returns '<unidentified>' if id is an empty string.

Types

type ID

type ID struct {
	// contains filtered or unexported fields
}

ID is a string-based unique identifier.

Many objects use a string as an identifier, and in many cases that string is a UUID.

ID encapsulates some common behavior of such IDs, such as simple validation and rendering logic without *requiring* that they be a UUID.

IDs are represented as a regular string when encoded as JSON.

ID is intended to be embedded into a more specific identifier type.

func (*ID) GenerateUUID

func (id *ID) GenerateUUID()

GenerateUUID sets the ID to a new random UUID. It panics if the ID is not empty.

func (ID) Get

func (id ID) Get() string

Get returns the ID as a string, or panics if it is invalid.

func (ID) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*ID) MustParse

func (id *ID) MustParse(s string)

MustParse sets the ID to s. It panics if s is empty.

func (ID) MustValidate

func (id ID) MustValidate()

MustValidate panics if the ID is not valid.

func (*ID) Parse

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

Parse sets the ID to s. It returns an error if s is empty.

func (*ID) Scan

func (id *ID) Scan(v interface{}) error

Scan implements the sql.Scanner interface for database deserialization.

func (ID) String

func (id ID) String() string

String returns a human-readable representation of the ID, which may not be the complete or valid ID.

Use Value() to get a copy a valid ID represented as a string.

func (*ID) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(data []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (ID) Validate

func (id ID) Validate() error

Validate returns an error if the ID is not valid.

func (ID) Value

func (id ID) Value() (driver.Value, error)

Value implements the driver.Valuer interface for database serialization.

Jump to

Keyboard shortcuts

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