shorter

package
v0.0.0-...-4450389 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package `shorter` is a name shorting service backed by MongoDB.

Index

Constants

View Source
const (
	KeyId  = "_id"
	KeyUri = "uri"

	MinAbbrvLen = 11
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Names

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

`Names` maintains a mapping between long names and short ids in a Mongo collection.

`Shorten()` returns a known id or creates a new `<IdPrefix>xX...` id based on a hash of `<UriPrefix>:<namespace>:<name>`. Each shortener can be assigned a different uppercase `IdPrefix` to ensure that ids are globally unique. `x` is always a lowercase alphanumeric character to separate the prefix from the hash. The rest `X...` of the hash can contain uppercase or lowercase alphanumeric characters. The `UriPrefix` is usually left at its default value `ngn`, for NoG Name.

`Find()` works like `Shorten()` but returns an error if the name does not yet exist.

The shortener uses approximately `MinAbbrvLen*6 - 1 = 65` bits of a secure hash for `xX`, so that ids are likely to be unique even without the prefix. A name shortener creates longer ids if it detects name collisions.

func NewNames

func NewNames(conn *mgo.Session, cfg *NamesConfig) (*Names, error)

func (*Names) Find

func (ns *Names) Find(namespace, name string) (string, error)

func (*Names) ListShortAll deprecated

func (ns *Names) ListShortAll(namespace string) ([]string, error)

Deprecated: Don't use `ListShortAll()` to find names. Instead use a higher service that has the list.

func (*Names) Shorten

func (ns *Names) Shorten(namespace, name string) (string, error)

type NamesConfig

type NamesConfig struct {
	Collection string
	IdPrefix   string
	UriPrefix  string
}

Jump to

Keyboard shortcuts

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