Fast url shortner written entirely in Go using the gin framework.
GET
/api/get
(first reads the cache, then the db.)
name type data type description Url required String shortend url
http code content-type response 200
application/json
Url body
400
application/json
{"message":"Reason"}
404
application/json
{"message":"Url was not found."}
curl -X GET -H "Content-Type: application/json" http://localhost:3000/api/get?Url=http://localhost:3000/hash
GET
/api/get_from_id
(first reads the cache, then the db, but uses unique id of a shortend url.)
name type data type description unique_id required String shortend url's id
http code content-type response 200
application/json
Url body
400
application/json
{"message":"Reason"}
404
application/json
{"message":"Url was not found."}
curl -X GET -H "Content-Type: application/json" http://localhost:3000/api/get_from_id?Url=http://localhost:3000/hash
POST
/api/set
(Creates and stores a new shortend url.)
name type data type description Url required String Original url
http code content-type response 201
application/json
Url body
400
application/json
{"message":"Reason"}
500
application/json
{"message":"Failed to set db."}
curl -X POST -H "Content-Type: application/json" --data '{"Url":"https://example.com"}' http://localhost:3000/api/set
The program expects these environment variables :
# defaults to 3000
PORT=3000
# defaults to http://localhost:3000
# this is what you would set as your base domain.
BASE_URL="http://localhost:3000"
# optionally you can provide GIN_MODE to get or remove log messages
# from the gin framework.
# defaults to debug
GIN_MODE="debug" # release, debug
clone and run using go cli.
git clone --depth 1 https://github.com/prashantrahul141/taurl && cd taurl && go run .