hashid

package
v1.36.4 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MalformedHashId = errors.New("Hash id is malformed")

Functions

func Decode

func Decode(hashid string) ([]int, error)

func DecodeKey

func DecodeKey(ctx context.Context, encoded string) (db.Key, error)

func Encode

func Encode(numbers ...int) string

func EncodeKey

func EncodeKey(ctx context.Context, key interface{}) string

EncodeKey encodes a key to a string using hashid encoding The key parameter accepts any type that implements the Key interface

func GetNamespace

func GetNamespace(ctx context.Context, hashid string) (string, error)

func IgnoreFieldMismatch

func IgnoreFieldMismatch(err error) error

IgnoreFieldMismatch is a helper for field mismatch errors

func KeyExists

func KeyExists(ctx context.Context, encoded string) (bool, error)

func MustDecodeKey

func MustDecodeKey(ctx context.Context, encoded string) db.Key

func RegisterNamespace

func RegisterNamespace(name string, id int64)

RegisterNamespace caches a namespace mapping

Types

type Key

type Key interface {
	Kind() string
	IntID() int64
	StringID() string
	Namespace() string
}

Key interface for encoding/decoding Note: Due to Go's strict interface matching, this interface defines Parent() as returning interface{} to allow any key type to be passed

type KeyWithParent

type KeyWithParent interface {
	Key
	Parent() interface{}
}

KeyWithParent is for keys that have a parent

type Model

type Model struct {
	Id_       string
	CreatedAt time.Time
	UpdatedAt time.Time
	Deleted   bool
}

type Namespace

type Namespace struct {
	// Included for compatibility with namespace models
	Model

	IntId int64
	Name  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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