{"id":20558512,"url":"https://github.com/ravikisha/urlshortener","last_synced_at":"2026-05-19T03:21:59.322Z","repository":{"id":234908725,"uuid":"789725005","full_name":"Ravikisha/URLShortener","owner":"Ravikisha","description":"A URL Shortener application built in Go, which allows users to generate short links for long URLs. It uses Redis as a database to store the short URLs and includes an IP-based rate limiter to control the number of requests allowed per user.","archived":false,"fork":false,"pushed_at":"2024-11-04T14:30:26.000Z","size":100,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-16T03:44:21.877Z","etag":null,"topics":["golang","rate-limiting","redis","web"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ravikisha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-21T11:40:09.000Z","updated_at":"2024-11-04T15:41:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"8cbe1063-aad4-469b-a05a-724b610caf0f","html_url":"https://github.com/Ravikisha/URLShortener","commit_stats":null,"previous_names":["ravikisha/urlshortener"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ravikisha%2FURLShortener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ravikisha%2FURLShortener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ravikisha%2FURLShortener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ravikisha%2FURLShortener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ravikisha","download_url":"https://codeload.github.com/Ravikisha/URLShortener/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234254047,"owners_count":18803446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","rate-limiting","redis","web"],"created_at":"2024-11-16T03:44:25.655Z","updated_at":"2026-05-19T03:21:59.280Z","avatar_url":"https://github.com/Ravikisha.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Poster](./docs/banner.png)\n# URL Shortener\n\n\u003cp float=\"left\"\u003e\n  \u003cimg src=\"https://shields.io/badge/Go-00ADD8?style=for-the-badge\u0026logo=go\u0026logoColor=white\" /\u003e\n    \u003cimg src=\"https://shields.io/badge/Redis-DC382D?style=for-the-badge\u0026logo=redis\u0026logoColor=white\" /\u003e\n    \u003cimg src=\"https://shields.io/badge/Docker-2496ED?style=for-the-badge\u0026logo=docker\u0026logoColor=white\" /\u003e\n    \u003cimg src=\"https://shields.io/badge/Fiber-00ADD8?style=for-the-badge\u0026logo=fiber\u0026logoColor=white\" /\u003e\n    \u003cimg src=\"https://shields.io/badge/Rate%20Limiting-FFA500?style=for-the-badge\" /\u003e\n\u003c/p\u003e\n\nA URL Shortener application built in Go, which allows users to generate short links for long URLs. It uses Redis as a database to store the short URLs and includes an IP-based rate limiter to control the number of requests allowed per user.\n\n## Features\n\n- **URL Shortening**: Generate short, unique URLs.\n- **Custom Short URLs**: Users can provide a custom alias for the shortened URL.\n- **Rate Limiting**: Limits requests per IP to prevent abuse, with a reset interval.\n- **Redis Database**: Stores mappings between original and shortened URLs.\n- **Docker Setup**: Includes Docker support for easy Redis setup.\n\n## Prerequisites\n\n- Go 1.19 or higher\n- Redis server (can be set up via Docker)\n- [gofiber/fiber](https://github.com/gofiber/fiber) for the web framework\n- [godotenv](https://github.com/joho/godotenv) for managing environment variables\n\n## Installation\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/Ravikisha/URLShortener.git\n   cd URLShortener\n   ```\n\n2. Install dependencies:\n   ```bash\n   go mod tidy\n   ```\n\n3. Set up the environment variables by creating a `.env` file in the project root with the following content:\n   ```plaintext\n   DB_ADDR=\"localhost:6379\"        # Redis address\n   DB_PASSWORD=\"\"                  # Redis password if any\n   APP_PORT=\":6767\"                # Application port\n   DOMAIN=\"localhost:6767\"         # Domain to use for shortened URLs\n   APP_QUOTA=10                    # Rate limit quota per IP\n   ```\n\n4. Run the application:\n   ```bash\n   go run main.go\n   ```\n\n### Running Redis with Docker\n\nTo set up Redis using Docker, run the following command:\n```bash\ndocker run --name url-shortener-redis -p 6379:6379 -d redis\n```\n\n## API Endpoints\n\n### 1. Shorten URL\n\n**Endpoint:** `/api/v1`\n\n**Method:** `POST`\n\n**Request Body:**\n```json\n{\n  \"url\": \"https://your-long-url.com\",\n  \"short\": \"customAlias\",         // Optional custom short URL alias\n  \"expiry\": 24                    // Optional expiry in hours, defaults to 24 hours\n}\n```\n\n**Response:**\n```json\n{\n  \"url\": \"https://your-long-url.com\",\n  \"short\": \"localhost:6767/customAlias\",\n  \"expiry\": 24,\n  \"x-rate-remaining\": 9,\n  \"x-rate-limit-reset\": 30\n}\n```\n\n### 2. Resolve Short URL\n\n**Endpoint:** `/:url`\n\n**Method:** `GET`\n\n**Description:** Redirects to the original URL associated with the short URL.\n\n## Environment Variables\n\nThe `.env` file should contain:\n\n- `DB_ADDR`: Redis server address.\n- `DB_PASSWORD`: Redis server password, if any.\n- `APP_PORT`: The port on which the application will run.\n- `DOMAIN`: The domain to prepend to generated short links.\n- `APP_QUOTA`: Maximum number of API requests allowed per IP within a specified time frame.\n\n## Docker Setup\n\nTo start both the Go application and Redis using Docker, follow these steps:\n\n1. Build and run project:\n   ```bash\n   docker-compose up -d\n   ```\n\n2. Start the Go application:\n   ```bash\n   go run main.go\n   ```\n\n## Folder Structure\n\n```\n├── main.go                # Entry point of the application\n├── routes                 # Contains route handlers for API endpoints\n│   ├── shorten.go         # Handles URL shortening logic\n│   └── resolve.go         # Handles URL resolution logic\n├── database               # Contains database client initialization\n├── helpers                # Utility functions\n└── .env                   # Environment variables for configuration\n```\n\n![Diagram](./docs/diagram.png)\n\n## Contributing\n\n1. Fork the repository.\n2. Create a feature branch.\n3. Commit your changes.\n4. Push the branch.\n5. Open a pull request.\n\n## License\n\nThis project is licensed under the MIT License.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fravikisha%2Furlshortener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fravikisha%2Furlshortener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fravikisha%2Furlshortener/lists"}