Short - simple go url shortener
Go to file
2024-08-14 09:14:37 +02:00
.github/workflows chore: update actions 2024-05-13 13:37:59 +02:00
internal/shortie fix(deps): update module github.com/valyala/fasthttp to v1.55.0 2024-06-17 15:43:44 +00:00
templates Delete old templates and add response.html that deals with all responses 2019-09-19 16:23:49 +02:00
.dockerignore Add Dockerfile for building standalone image 2019-03-18 16:23:39 +01:00
.gitignore chore: updates readme and .gitignore 2022-05-19 16:05:20 +02:00
CHANGELOG.md Bump version to 1.0.1 2019-05-01 16:49:12 +02:00
Dockerfile chore(deps): update golang docker tag to v1.23 2024-08-13 21:39:26 +00:00
go.mod fix(deps): update module github.com/valyala/fasthttp to v1.55.0 2024-06-17 15:43:44 +00:00
go.sum fix(deps): update module github.com/valyala/fasthttp to v1.55.0 2024-06-17 15:43:44 +00:00
LICENSE Add License 2019-03-18 16:23:52 +01:00
main.go feat: add healthz endpoint 2022-05-19 10:29:51 +02:00
README.md chore: updates readme and .gitignore 2022-05-19 16:05:20 +02:00
renovate.json chore(deps): add renovate.json 2022-09-27 08:39:52 +00:00

Short - simple go url shortener

License

Short is a very simple url shortener build in golang, the main focus is speed, not data is persisted, but can be dumped and restored.

Syntax is

Usage of short:
  -addr string
        Address to listen for connections (default "localhost")
  -cleanup int
        Cleanup interval in hours, default 1 (default 1)
  -domain string
        Domain to write to the URLs (default "localhost")
  -dumpFile string
        urls.json (default "Path to the file to dump the kv db")
  -exp int
        Default expiration time in hours, default 240 (default 240)
  -http
        proto to the base URL (HTTPS://localhost/path/... no real https here just to set the url (for like a proxy offloading https
  -path string
        Path to the base URL (https://localhost/PATH/...
  -port int
        Port to listen for connections (default 8080)
  -size int
        Define the size of the shortened String (default 10)
  -urlPort int
        Port to use for building URLs (default 443)
  -v    prints current version

Includes a Dockerfile to for a standalone docker image.

To shorten a URL just post on /, you will get a reply with the shortened URL

curl -X POST -d "url=http://google.com" http://localhost:8080/
[...]
URL shortened at: https://localhost:8080/9mbIcOwsVP
[...]

URLs missing a Scheme (http[s]://) will be defaulted to https

Dump/Restore endpoints

URLs for mapping data can be checked, listed, dumped and restored in the given endpoints (you might want (and you should) restrict access to this e.g. reverse proxy):

Show the number of mapped urls

$ curl http://localhost:8080/v1/count
X

Dumps the mapped url to json

$ curl http://localhost:8080/v1/dump
[...] #json of mapped urls

Dump the mapped url to -dump file (defaults to ./urls.json)

curl http://localhost:8080/v1/dumpToFile

Load url mappings from -dump file to in memory db

curl http://localhost:8080/v1/fromFile

Load url mappings from POST data (Assuming json data on save.json file)

curl -X POST http://localhost:8080/v1/fromPost \
-H "Content-Type: application/json" \
--data $(cat save.json )

HTML templates

A simple collection of html templates are put on templates folder, the templates I've used are based on @jspark721 "UI 404 PAGE" on freefrontend