This is a simple URL shortener written in Go that stores shortcodes in Redis and can be run using Docker Compose.
- Go (tested with version 1.19)
- Docker
- Docker Compose
- Clone this repository:
git clone https://github.com/janelh/shortcode.git
- Build the Docker image:
docker-compose build
- Run the Docker containers:
docker-compose up
The URL shortener should now be running at http://localhost:8080
To shorten a URL, send a POST request to the server with the original URL in the request body:
curl -X POST -d '{"url":"http://example.com"}' http://localhost:8080/urls
The server will respond with the shortened URL, which can be accessed by visiting the shortcode URL:
{
"http://localhost:8080/urls/abc123"
}
http://localhost:8080/urls/abc123 will redirect to http://example.com
The following environment variables can be used to configure the behavior of the URL shortener:
- RDS_HOST: the hostname or IP address of the Redis server
- RDS_PASSWORD: the password for the Redis server
- BASE_URL: the base URL of the shortener
These variables can be set in the .env file in the root of the project.