hexkey

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Package hexkey implements utilities for hexadecimal encoding of blob store keys.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotMyKey = errors.New("key does not match config")

ErrNotMyKey is a sentinel error reported by Decode when given a key that does not match the parameters of the config.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Prefix, if set, is prepended to all keys, separated from the remainder of
	// the key by "/".
	Prefix string

	// Shard, if positive, specifies a prefix length for each hex-encoded key,
	// that will be separated from the key by an intervening "/".
	// For example, if Shard is 2, a key "012345" becomes "01/012345".
	// If Shard ≤ 0, keys are not partitioned.
	Shard int
}

Config carries settings for the encoding and decoding of hex keys. The zero value is ready for use and encodes keys as plain hexadecimal strings.

func (Config) Decode

func (c Config) Decode(ekey string) (string, error)

Decode decodes the specified hex-encoded key according to c. If ekey does not match the expected format, it reports ErrNotMyKey. Otherwise, any error results from decoding the hexadecimal digits.

func (Config) Encode

func (c Config) Encode(key string) string

Encode encodes the specified key as hexadecimal according to c.

func (Config) WithPrefix added in v0.8.0

func (c Config) WithPrefix(pfx string) Config

WithPrefix returns a copy of c with its prefix set to pfx.

Jump to

Keyboard shortcuts

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