Documentation ¶
Overview ¶
Package shorteners provides utilities for retrieving information about URL shortening websites.
Index ¶
- Variables
- type CleanFunc
- type IsVanityFunc
- type Shortener
- func (s *Shortener) Clean(shortURL string) (string, error)
- func (s *Shortener) CleanURL(u *url.URL) (string, error)
- func (s *Shortener) CleanURLs(urls []string) ([]string, error)
- func (s *Shortener) GetIAShortcodes() ([]string, error)
- func (s *Shortener) IsVanity(shortcode string) bool
- func (s *Shortener) Sort(shortcodes []string)
Constants ¶
This section is empty.
Variables ¶
var Allst = &Shortener{ Name: "a-ll-st", Host: "a.ll.st", Prefix: "http://a.ll.st/", Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Pattern: regexp.MustCompile(`^[0-9A-Za-z_]+$`), CleanFunc: func(shortcode string, u *url.URL) string { if strings.HasPrefix(shortcode, "scmf/") { shortcode = shortcode[strings.LastIndexByte(shortcode, '/')+1:] } return shortcode }, IsVanityFunc: func(shortcode string) bool { return len(shortcode) != 6 || strings.ContainsRune(shortcode, '_') }, HasVanity: true, }
Allst describes the Allstate a.ll.st link shortener.
var Bfytw = &Shortener{ Name: "bfy-tw", Host: "bfy.tw", Prefix: "https://bfy.tw/", Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Pattern: regexp.MustCompile(`^[0-9A-Za-z]+$`), CleanFunc: func(shortcode string, u *url.URL) string { return bfytwTrailing.ReplaceAllLiteralString(shortcode, "") }, HasVanity: false, }
Bfytw describes the bfy.tw link shortener. All URLs redirect to https://lmgtfy.app/?q=<query>
var Debli = &Shortener{ Name: "deb-li", Host: "deb.li", Prefix: "https://deb.li/", Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Pattern: regexp.MustCompile(`^[0-9A-Za-z]+$`), CleanFunc: func(shortcode string, u *url.URL) string { if strings.ContainsRune(shortcode, '@') { return "" } shortcode = strings.TrimPrefix(shortcode, "p/") if strings.ContainsRune(shortcode, '/') || strings.ContainsRune(shortcode, '.') { return "" } return shortcode }, HasVanity: true, }
Debli describes the Debian deb.li link shortener.
var GoHawaiiEdu = &Shortener{ Name: "go-hawaii-edu", Host: "go.hawaii.edu", Prefix: "https://go.hawaii.edu/", Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Pattern: regexp.MustCompile(`^[0-9A-Za-z]+$`), CleanFunc: func(shortcode string, u *url.URL) string { if strings.ContainsRune(shortcode, '/') { return "" } switch shortcode { case "admin", "submit": return "" } return strings.TrimSuffix(shortcode, "+") }, HasVanity: false, }
GoHawaiiEdu describes the University of Hawaii go.hawaii.edu link shortener.
var Lookup = make(map[string]*Shortener)
var MobyTo = &Shortener{ Name: "moby-to", Host: "moby.to", Prefix: "http://moby.to/", Alphabet: "0123456789abcdefghijklmnopqrstuvwxyz", Pattern: regexp.MustCompile("^[0-9a-z]+$"), CleanFunc: func(shortcode string, u *url.URL) string { if strings.ContainsRune(shortcode, '/') { return "" } if i := strings.IndexAny(shortcode, ":-+*."); i != -1 { shortcode = shortcode[:i] } return strings.ToLower(shortcode) }, HasVanity: false, }
MobyTo describes the Mobypicture moby.to link shortener.
var Qrcx = &Shortener{ Name: "qr-cx", Host: "qr.cx", Prefix: "http://qr.cx/", Alphabet: "123456789ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Pattern: regexp.MustCompile(`^[1-9A-HJ-Za-z]+$`), CleanFunc: cleanQrcx, HasVanity: false, }
Qrcx describes the qr.cx link shortener.
var Rbgy = &Shortener{ Name: "rb-gy", Host: "rb.gy", Prefix: "https://rb.gy/", Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Pattern: regexp.MustCompile(`^[0-9A-Za-z]+$`), CleanFunc: func(shortcode string, u *url.URL) string { shortcode = trimAfterAny(shortcode, "+/._-:$@◄") shortcode = rbgyNonAlpha.ReplaceAllLiteralString(shortcode, "") if len(shortcode) > 6 { shortcode = shortcode[:6] } return strings.ToLower(shortcode) }, HasVanity: false, }
Rbgy describes the rb-gy link shortener, which is powered by Rebrandly.
var RedHt = &Shortener{ Name: "red-ht", Host: "red.ht", Prefix: "https://red.ht/", Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Pattern: regexp.MustCompile(`^[0-9A-Za-z\-_]+$`), CleanFunc: func(shortcode string, u *url.URL) string { if strings.ContainsRune(shortcode, '.') { return "" } return trimAfterByte(shortcode, '@') }, IsVanityFunc: func(shortcode string) bool { return strings.ContainsAny(shortcode, "-_") }, HasVanity: true, }
RedHt describes the Red Hat red.ht link shortener.
var SUconnEdu = &Shortener{ Name: "s-uconn-edu", Host: "s.uconn.edu", Prefix: "https://s.uconn.edu/", Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Pattern: regexp.MustCompile(`^[0-9A-Za-z\-_]+$`), CleanFunc: func(shortcode string, u *url.URL) string { if strings.ContainsRune(shortcode, '/') { return "" } return strings.ToLower(shortcode) }, IsVanityFunc: func(shortcode string) bool { return strings.ContainsRune(shortcode, '-') }, HasVanity: true, }
SUconnEdu describes the University of Connecticut s.uconn.edu link shortener.
var ShortIm = &Shortener{ Name: "short-im", Host: "short.im", Prefix: "http://short.im/", Alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Pattern: regexp.MustCompile(`^[0-9A-Za-z\-_]+$`), CleanFunc: cleanShortIm, HasVanity: true, }
ShortIm describes the Short.i'm short.im link shortener.
Functions ¶
This section is empty.
Types ¶
type IsVanityFunc ¶
type Shortener ¶
type Shortener struct { Name string Host string Prefix string Alphabet string Pattern *regexp.Regexp CleanFunc CleanFunc IsVanityFunc IsVanityFunc HasVanity bool }
func (*Shortener) Clean ¶
Clean extracts the shortcode from a URL. An empty string is returned when no shortcode can be found.
func (*Shortener) CleanURL ¶
CleanURL extracts the shortcode from a URL. An empty string is returned when no shortcode can be found.
func (*Shortener) CleanURLs ¶
CleanURLs extracts, deduplicates, and sorts the shortcodes in slice of URLs.
func (*Shortener) GetIAShortcodes ¶
GetIAShortcodes queries all the shortcodes that have been archived on the Internet Archive.