This is a backend API built with Go. It is designed for scalability and simplicity.It serves as a URL shortener service with features like generating and retrieving shortened URLs.
-
Clone the repository:
git clone https://github.com/tin3ga/shortly.git cd shortly -
Install dependencies:
go mod tidy
-
Create a metadefender cloud account for a free api key. Add key in the .env files
-
Configure .env file from sample:
PORT=8088 DATABASE_URL=postgresql://postgres:mypassword@localhost:5432/postgres?sslmode=disable URL=http://localhost:8088/api/v1/ REDIS_ADDR=localhost:6379 REDIS_PASSWORD= REDIS_DB=0 caching_enabled=true cache_TTL=10 rate_limiting_enabled=True max_connections_limit=1000 expiration=1 api_Key=sample_api skip_failed_requests=false skip_successful_requests=false metrics_title=Shortly Monitor metrics_font_URL=https://fonts.googleapis.com/css2?family=Roboto:wght@200;400&display=swap jwt_secret=my_secret
-
Setup a postgres database and redis db
-
Replace the connection details in the env files
-
Add a GOOSE_DBSTRING in makefile
-
Run make to set up migrations, dev dependencies etc.
make help
-
Run the application
go run main.go
-
Swagger Documentation Access API documentation at:
http://localhost:8088/swagger/index.html
Using Docker:
docker compose up
goose -dir ./sql/schema/ postgres postgresql://postgres:mypassword@localhost:5432/postgres?sslmode=disable upFor production, ensure you:
-
Use a secure .env file
-
Build the binary:
go build -o app main.go
-
Deploy the binary or container to your server or cloud provider.
Using hey to test rate limiter
./hey -n 1000 -c 10 http://localhost:8088/ap1/v1/links/all
Using autocannon to test caching enable or disable caching in the .env file
autocannon -d 20 -c 50 --renderStatusCodes http://localhost:8088/api/v1/links/allThis project is licensed under the MIT license.
© 2025 tin3ga