A simple URL shortening service written in Go.
The service provides a HTTP API which supports a couple of basic operations.
Note: these examples assume the service is accessible at http://localhost:5000
POST /shorten
Host: http://localhost:5000
Content-Type: application/json
{
"url": "http://example.com/really/long/url?foo=bar123456789"
}
---
HTTP/1.1 200 OK
Content-Type: application/json
{
"long_url": "http://example.com/really/long/url?foo=bar123456789",
"short_url": "http://localhost:5000/cTRD2S4d"
}
GET /cTRD2S4d
Host: http://localhost:5000
---
HTTP/1.1 301 Moved Permanently
Location: http://example.com/really/long/url?foo=bar123456789
Running the service locally requires Docker and Docker Compose.
A Makefile is provided. This collects commonly-used development commands into easy-to-remember aliases.
To run the service:
$ make run
This will start the service running in the background. By default, it is is configured to listen for new connections at http://localhost:5000.
To stop the service:
$ make stop
The service has a suite of unit tests, which can be run as follows:
$ make test
Trunc comes with a command line tool that you can use to quickly generate short URLs:
$ go install ./cmd/trunc
$ trunc http://example.com/really/long/url?foo=bar123456789
------------------------------
http://localhost:5000/ko9RVl4o
------------------------------
For configuration info, see
$ trunc help