influxid

package
v2.1.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const IDLength = 16

IDLength is the exact length a string (or a byte slice representing it) must have in order to be decoded into a valid ID.

Variables

View Source
var (
	// ErrInvalidID signifies invalid IDs.
	ErrInvalidID = errors.New("invalid ID")

	// ErrInvalidIDLength is returned when an ID has the incorrect number of bytes.
	ErrInvalidIDLength = errors.New("id must have a length of 16 bytes")
)

Functions

This section is empty.

Types

type ID

type ID uint64

ID is a unique identifier.

Its zero value is not a valid ID.

func IDFromString

func IDFromString(str string) (ID, error)

IDFromString creates an ID from a given string.

It errors if the input string does not match a valid ID.

func MustIDFromString

func MustIDFromString(s string) ID

MustIDFromString is like IDFromString but panics if s is not a valid base-16 identifier.

func (*ID) Decode

func (i *ID) Decode(b []byte) error

Decode parses b as a hex-encoded byte-slice-string.

It errors if the input byte slice does not have the correct length or if it contains all zeros.

func (*ID) DecodeFromString

func (i *ID) DecodeFromString(s string) error

DecodeFromString parses s as a hex-encoded string.

func (ID) Encode

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

Encode converts ID to a hex-encoded byte-slice-string.

It errors if the receiving ID holds its zero value.

func (ID) GoString

func (i ID) GoString() string

GoString formats the ID the same as the String method. Without this, when using the %#v verb, an ID would be printed as a uint64, so you would see e.g. 0x2def021097c6000 instead of 02def021097c6000 (note the leading 0x, which means the former doesn't show up in searches for the latter).

func (ID) MarshalText

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

MarshalText encodes i as text. Providing this method is a fallback for json.Marshal, with the added benefit that IDs encoded as map keys will be the expected string encoding, rather than the effective fmt.Sprintf("%d", i) that json.Marshal uses by default for integer types.

func (*ID) Set

func (i *ID) Set(s string) error

func (ID) String

func (i ID) String() string

String returns the ID as a hex encoded string.

Returns an empty string in the case the ID is invalid.

func (*ID) UnmarshalText

func (i *ID) UnmarshalText(b []byte) error

UnmarshalText decodes i from a byte slice. Providing this method is also a fallback for json.Unmarshal, also relevant when IDs are used as map keys.

func (ID) Valid

func (i ID) Valid() bool

Valid checks whether the receiving ID is a valid one or not.

Jump to

Keyboard shortcuts

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