A URL shortener written in Go. Supporting both in-memory and PostgreSQL storage backends.
- Wait for Postgres DB to come live before trying to connect
- Modify in memory storage to use
sync.RWMutex
instead of maps - Create a frontend under
/website
- Return saved slug if URL already exists in Storage
- Ability to choose custom slug
- Debug logging
- Add a
deploy/docker-compose.yml
The following endpoints are available:
GET /shorten?url=:URL
: Shorten a new URL.GET /:slug
: Redirect to the original URL.
Example:
curl 'http://localhost:8080/shorten?url=https://example.com'
Response:
{ "short_url": "pvog" }
Clone the repository:
git clone https://github.com/mradigen/chota
cd chota
-
Build the Docker image:
make docker
-
Copy the
.env.example
file and edit it as needed (refer configuration):cp .env.example .env
-
Run the Docker container:
docker run -p 8080:8080 --env-file=.env chota
-
Build the project:
make build
-
Run:
./chota
The application supports environment-based configuration:
Variable | Default | Description |
---|---|---|
PORT |
8080 |
Port for the HTTP server. |
STORAGE_MODE |
memory |
Storage backend: memory or postgres . |
DATABASE_URL |
postgres://... |
Connection string for PostgreSQL. Used only if STORAGE_MODE=postgres |
BIND_ADDRESS |
127.0.0.1 |
Address to listen on. |
DEBUG (unimplemented) |
false |
Log debug activity. |
Use the provided kubernetes.yml
file to deploy the application to a Kubernetes cluster:
make kubernetes
or
kubectl apply -f deploy/kubernetes.yml
make run
Currently there is a very basic test setup. Run the unit and integration tests using:
make test
Contributions are highly encouraged! Please open an issue or submit a pull request with your changes.