This project is a URL shortener built with Go and Echo framework, utilizing MySQL for data storage.
Feel free to check the initial design of the database schema here.
- Introduction
- Features
- Technologies
- API Endpoints
- Installation
- Usage
- Directory Structure
- Commit Tag Meanings
- Changelog
- Security
- Contributing
- License
The project is a URL shortener that allows users to shorten long URLs into short, easy-to-remember URLs. It also provides a redirection service that allows users to redirect to the original URL by visiting the short URL. The project also includes user authentication to allow users to create accounts and manage their shortened URLs.
- User authentication
- URL shortening
- URL redirection
- Go
- Echo
- MySQL
The following are the API endpoints available in the application:
POST /auth/register
: Register a new userPOST /auth/login
: Login a user
POST /url/shorten
: Shorten a URL
GET /clicks/:shortURL
: Redirect to the original URL
-
Clone the repository:
git clone https://github.com/abdullahkabakk/url-shortener.git
-
Change directory to the project root:
cd url-shortener
-
Create a
.env
file in the root directory and add the following environment variables:DB_USERNAME=<your_mysql_username> DB_PASSWORD=<your_mysql_password> DB_HOST=<mysql_host> DB_PORT=<mysql_port> DB_NAME=<database_name> HOST=<host_name> PORT=<port_name> MIGRATIONS_DIR=<migrations_dir> JWT_SECRET_KEY=<jwt_key>
-
Install the dependencies:
go mod download
-
Run the application:
go run main.go
-
The application should now be running on
http://<HOST>:<PORT>
. -
You can now access the application on your browser or using a tool like Postman.
-
You can also run the tests using the following command:
go test ./...
-
You can also make coverage reports using the following command:
make report
The project uses Golang Migrate for database migrations. But doesn't include migration files. You need to create migration files for user, url, and click tables.
To create a user, run the following command:
curl -X POST http://localhost:8080/auth/register -d '{"username": "user", "password": "password"}'
To log in a user, run the following command:
curl -X POST http://localhost:8080/auth/login -d '{"username": "user", "password": "password"}'
To shorten a URL, run the following command:
curl -X POST http://localhost:8080/url/shorten -d '{"url": "https://www.google.com"}' -H "Authorization
To redirect to the original URL, run the following command:
curl -X GET http://localhost:8080/clicks/<shortURL>
The project's directory structure is as follows:
.
├── internal
│ ├── app
│ │ ├── handler
│ │ │ ├── auth
│ │ │ └── url
│ │ ├── models
│ │ │ ├── url
│ │ │ └── user
│ │ ├── repository
│ │ │ ├── auth
│ │ │ └── url
│ │ └── services
│ │ ├── auth
│ │ └── url
│ ├── config
│ ├── infrastructure
│ │ ├── database
│ │ │ └── migrations
│ │ └── http
│ ├── mocks
│ └── utils
...
Commit tags convey the nature of changes made in the codebase. Below are common commit tags and their meanings:
Tag | Description | Example Commit Message |
---|---|---|
[feat] | New feature or significant enhancement | [feat] Implement user authentication |
[fix] | Bug fix or correction to existing functionality | [fix] Resolve issue with user registration |
[chore] | Routine tasks, maintenance, or tooling changes | [chore] Update dependencies |
[docs] | Changes or additions to documentation | [docs] Update installation guide |
[style] | Code style changes | [style] Format code according to style guide |
[refactor] | Code restructuring or optimization | [refactor] Simplify user profile rendering |
[test] | Adding or modifying tests | [test] Add unit tests for authentication |
[ci] | Changes to continuous integration (CI) configuration | [ci] Update Travis CI configuration |
[build] | Changes affecting build system or dependencies | [build] Upgrade webpack to version 5 |
[perf] | Performance improvements or optimizations | [perf] Optimize database queries |
All significant updates to this project will be meticulously documented in this log.
If you discover any security vulnerabilities within the URL shortener project, please follow these steps to report them: Security Policy
Find out how to contribute to the URL Shortener project by following the guidelines provided in the CONTRIBUTING file.
This project is open-source and is available under the MIT License.