A microservice used to shorten URLs built with Go.
This project was built using Echo and offers the option between two data stores:
- Badger - Embedded Go Key/Value Database as a single standalone executable. Great for light / mid-tier usage.
- Mongo + go-cache - Allows for greater control of data storage and clustered environments.
Microservice runs on http://localhost:8080 by default.
cd $GOPATH go get github.com/roboncode/shorty-go cd github.com/roboncode/shorty-go dep ensure # To run with BadgerDb go run main.go # To run with MongoDb make mongo STORE=mongo go run main.go Give the code a quick spin by building a single exec with no external dependencies. Optional config.yaml file can be used for configuration or you can configure it as part of the command line.
make standalone # Run with BadgerDb # Run on Linux make run # Run on Mac OSX make run_osx # Run on Windows make run_win # Startup MongoDb instance make mongo # Run on Linux STORE=mongo make run # Run on Mac OSX STORE=mongo make run_osx # Run on Windows STORE=mongo make run_win make build make start # Run with BadgerDb make dev # Run with MongoDb make mongo STORE=mongo make dev make test The default API key in config.yaml is shorty. The web app is built with Vue.js. The source is found in the web-client directory.
GET /admin See notes web-client/README.md for instructions on running and building the web app.
The API is pretty simple.
Authentication required - uri?key=:authKey POST /shorten body{ url:String } GET /links?l=:limit&s=:skip (Mongo works, Badger in progress) GET /links/:code DELETE /links/:code No Authentication required GET /admin Admin SPA GET / Landing page GET /:code Redirect to long url GET /* 404 page Shorty uses Viper to handle configuration. The config.yaml contains all the configurable variables and default values. 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/shorty Feel free to fork it, hack it and use it any way you please.
MIT License