Golink
The Golink crate is an engine for resolving URLs for link shortening services. You provide a link to expand and a function for mapping short URLs to long URLs, and this crate will:
-
Normalize your input to ignore case and hyphenation:
http://go/My-Serviceandhttp://go/myserviceare treated as the same input into your mapping function -
Append secondary paths to your resolved URL: if your mapping function returns
http://example.comfor the given shortlinkfoo, then a request tohttp://go/foo/bar/bazwill resolve tohttp://example.com/foo/bar/baz -
Apply templating, when applicable: Using a simple templating language, your long URLs can powerfully place remaining path segments in your URL ad-hoc and provide a fallback value when there are no remaining path segments. For example, if your mapping function returns for the given shortlink
prsthe following URL:https://github.com/pulls?q=is:open+is:pr+review-requested:{{ if path }}{ path }{{ else }}@me{{ endif }}+archived:falsethen a request to
http://go/prsreturns the URL to all Github PRs to which you are assigned:https://github.com/pulls?q=is:open+is:pr+review-requested:@me+archived:falseand a request to
http://go/prs/jameslittle230returns the URL to all Github PRs to which I (@jameslittle230) am assigned:https://github.com/pulls?q=is:open+is:pr+review-requested:jameslittle230+archived:false
This resolver performs all the functionality described in Tailscale's Golink project
This crate doesn't provide a web service or an interface for creating shortened links; it only provides an algorithm for resolving short URLs to long URLs.
Usage
The Golink crate doesn't care how you store or retrieve long URLs given a short URL;
you can store them in memory, in a database, or on disk, as long as they are retrievable
from within a closure you pass into the resolve() function:
let resolved = resolve
match computed