Documentation ¶
Overview ¶
Package ident contains utilities for representing arbitrary identifiers.
Index ¶
- Variables
- func Format(id string) string
- type ID
- func (id *ID) GenerateUUID()
- func (id ID) Get() string
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) MarshalText() ([]byte, error)
- func (id *ID) MustParse(s string)
- func (id ID) MustValidate()
- func (id *ID) Parse(s string) error
- func (id *ID) Scan(v interface{}) error
- func (id ID) String() string
- func (id *ID) UnmarshalJSON(data []byte) error
- func (id *ID) UnmarshalText(data []byte) error
- func (id ID) Validate() error
- func (id ID) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyID = errors.New("ID is empty")
ErrEmptyID indicates an attempt was made to use an uninitialized ID value.
var ErrIDNotEmpty = errors.New("can not replace existing ID")
ErrIDNotEmpty indicates an attempt was made to overwrite an existing ID value.
Functions ¶
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) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (ID) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (ID) 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 ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*ID) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.