clid

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package clid implements a prefixed ulid ID type.

Index

Constants

View Source
const (
	// Separator for string encoding, we like '-' for showing them in urls.
	Separator = "-"
	// must be this length, to prevent above through large strings and to make storage size predictable.
	PrefixSize = 4
	// ZeroPrefix is shown when a zero value is encoded, for recognizing that case easily.
	ZeroPrefix = "zzzz"
	// StorageSize determines the size of our identifier when stored, useful for sql schemas.
	StorageSize = 26 + PrefixSize + 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ID

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

ID implements a prefixed ULID identifier.

func New

func New(prefix string) (id ID)

New with default tme and entropy sources and panic when it fails.

func NewFromParts

func NewFromParts(prefix string, ms uint64, entr io.Reader) (id ID, err error)

NewFromParts creates an id from its parts.

func (ID) MarshalGQL

func (id ID) MarshalGQL(w io.Writer)

MarshalGQL marshals the identifier.

func (ID) MarshalJSON

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

MarshalJSON implements the json.Marshaler interface.

func (*ID) Scan

func (id *ID) Scan(v any) error

Scan implements the sql.Scanner.

func (ID) String

func (id ID) String() string

String implements the fmt.Stringer interface.

func (*ID) UnmarshalGQL

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

UnmarshalGQL implements the graphql.Unmarshaler interface.

func (*ID) UnmarshalJSON

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

UnmarshalJSON implements the json.Unmarshaler interface.

func (ID) Value

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

Value implements the driver Valuer interface.

type ScanError

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

ScanError describes a failure to scan an ID.

func (ScanError) Error

func (e ScanError) Error() string

Jump to

Keyboard shortcuts

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