by lgo

GitHub Readme.md


A small and simple URL shortener.



For information on building, see the section at the end.


ADMIN_KEY=<secret> PORT=80 GOLINKS_ENV=prod ./golinks
  • ADMIN_KEY is used for authenticating the administrative endpoints and is required.
  • PORT is optional, defaulting to 8080.
  • GOLINKS_ENV defaults to dev. prod runs on, dev runs on
  • GOLINKS_LOGLEVEL defaults to info, and has the options debug, info, warn.
  • GOLINKS_STORE defaults to dict, and has the options dict, redis.

Adding short links

curl localhost/admin/api/links/htn \
  -X POST -H "Content-type: application/json" \
  -H "Golink-Auth: <ADMIN_KEY>" \
  -d '{"url": "https://hackthenorth.com"}'

curl localhost/htn
> <a href="https://hackthenorth.com">See Other</a>.
# A 304 Redirect (temporary redirect)

To see what a short link is set to, along with the metrics

curl localhost/admin/api/links/htn \
  -H "Golink-Auth: <ADMIN_KEY>" \
> {"url":"https://hackthenorth.com","metrics":0}

Storage configuration

The default simple setup uses an ephemeral dictionary, but if you wish to persist short links you can set up Redis with the following configuration:

REDIS_URL=<url> # defaults to "redis://h:@localhost:6379"
# Format: redis://h:<password>@<host>:<port>


If you're looking to just get started, there are pre-built binaries under Github Releases.

This library was built and only tested with go1.8.3. In order to use it, it also assumes you have this repo in your GOPATH, along with the vendored dependancies available.

go get "github.com/sirupsen/logrus"
go get "github.com/gorilla/mux"