Documentation
¶
Overview ¶
Package `shorter` is a name shorting service backed by MongoDB.
Index ¶
Constants ¶
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.