A simple URL shortener using Go and Mongo.
This project was built using Echo and offers two data stores:
- Badger - Embedded Go Key/Value Database for a simple standalone exec using
- Mongo - To handle clustered services such as in a Kubernetes environment
The Mongo database uses go-cache to ttl cache to prevent burdening the database with redundant requests.
make build
make start
Service will be available on http://localhost:8080
make standalone
make run
Service will be available on http://localhost:8080
go run main.go
The API is pretty simple.
Authentication required - uri?key=:authKey
POST /shorten body{ url:String }
GET /links?l=:limit&s=:skip *Mongo only
GET /links/:code
DELETE /links/:code
No Authentication required
GET / Landing page
GET /:code Redirect to long url
GET /* 404 page
This service uses Viper for it's configuration. The config.yaml contains all the configurable variables. You can also override any variables as environment variables. You will see examples of this in the docker-compose.yml. You can also set the variables from the command line.
ENV=prod STORE=mongo ./bin/urlshortener
Feel free to fork it, hack it and use it any way you please.
MIT License