A basic URL shortening service
This is a hobby project to learn Golang. The application has 2 components:
- Admin Service: This is a RESTful API server that allows users to shorten URLs. It provides
- A user interface for users to input long URLs and receive shortened versions.
 - A list of previously shortened URLs.
 
 - Url Redirector: This is a simple HTTP server that redirects requests for shortened URLs to their original long URLs.
 
url-shortener/
├── auth/               # JWT Authentication token validation and creation related code
├── cache/              # Redis Cache related code
├── configs/            # Configuration files. Base server, database, cache, etc.
├── db/                 # Postgres database object
├── models/             # Database models for URLs, Users and URL Redirection
├── server/             # Separate start points for admin and redirector services
├── urls/               # URL shortener related code for admin and redirector services
├── users/              # User related code for admin service
- Go 1.24.1 or later
 - Postgres 15 or later
 - Redis 7.4 or later
 - Docker (optional, for deployment)
 - Docker Compose (optional, for deployment)
 - Make sure you have the necessary permissions to run the application and access the database.
 
- Clone the repository:
git clone https://github.com/pratts/url-shortener.git cd url-shortener - Install dependencies:
go mod tidy
 - Set up the database:
- Create a Postgres database and user for the application.
 
 - Set up Redis:
- Install Redis and start the server.
 
 - Configure the application:
- Update the .env.example file with server, database and cache configurations
 - Rename the file to .env or create a new .env file with the same name and copy the parameters from .env.example
 
 - Run the applications on terminal:
- Start the admin service:
 
go run server/admin/main.go
- Start the redirector service:
 
go run server/redirector/main.go
- Alternatively, you can use Docker to run the application:
 
docker-compose up --build
- This will start the application and expose the admin and the redirector service on ports defined in .env file. It will start a separate postgres database on 5432 and redis server on 6379.
 
 - Access the application APIs:
- Admin service: 
http(s)://${host}$:{admin_port}/api/v1/swagger/index.html 
 - Admin service: 
 - Test the application:
- Create a user with the email and password
 - Login with the email and password and get the access token
 - Use the access token to access the APIs
 
 
The application deployed on railway at https://admin.tidylnk.com/
👤 Email: [email protected]
🔐 Password: demo123
- The API documentation is available at 
http(s)://${host}$:{admin_port}/api/v1/swagger/index.html - The API documentation is generated using the command:
 
go install github.com/swaggo/swag/cmd/swag@latest- To solve a dependency issue, run the following command:
 
go get github.com/jackc/pgx/v5/[email protected]- To generate the API documentation, run the following command:
 
swag init -d server/admin,urls,users,models