Giter Club home page Giter Club logo

url-shortener's Introduction

URL Shortener

Go Report Card Build Coverage Code Style License Go Version Run In Postman

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.

Table of Contents

Introduction

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.

Features

  • User authentication
  • URL shortening
  • URL redirection

Technologies

  • Go
  • Echo
  • MySQL

API Endpoints

The following are the API endpoints available in the application:

Auth

  • POST /auth/register: Register a new user
  • POST /auth/login: Login a user

URL

  • POST /url/shorten: Shorten a URL

Clicks

  • GET /clicks/:shortURL: Redirect to the original URL

Installation

  1. Clone the repository:

    git clone https://github.com/abdullahkabakk/url-shortener.git
  2. Change directory to the project root:

    cd url-shortener
  3. 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>
    
  4. Install the dependencies:

    go mod download
  5. Run the application:

    go run main.go
  6. The application should now be running on http://<HOST>:<PORT>.

  7. You can now access the application on your browser or using a tool like Postman.

  8. You can also run the tests using the following command:

    go test ./...
  9. You can also make coverage reports using the following command:

    make report

Database Migrations

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.

Usage

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>

Directory Structure

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 Tag Meanings

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

Changelog

All significant updates to this project will be meticulously documented in this log.

Security

If you discover any security vulnerabilities within the URL shortener project, please follow these steps to report them: Security Policy

Contributing

Find out how to contribute to the URL Shortener project by following the guidelines provided in the CONTRIBUTING file.

License

This project is open-source and is available under the MIT License.

url-shortener's People

Contributors

abdullahkabakk avatar

Watchers

 avatar

url-shortener's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.