Git Product home page Git Product logo

bizewskime_links's Introduction

Short Link Generator

This is a short link generator written in Go.
It provides an API endpoint for creating new short links and an endpoint to use the shot link.

This project is a learning exercise for me. This is my first Go application.
It is hosted on l.bizewski.me.

Technical and business considerations

  • This application is build using the hexagonal architecture. I know it is a bit overkill for this application, but I wanted to learn more about it.
  • Short codes are built using 3 random characters.
  • If generated short code already exists, it will generate a new one. It will try 10 times before giving up.
  • The application uses SQLite as a database. There is no need for a full-blown database for this application.

TODO:

  • Implement a database repository. Right now, it is using a memory repository,
  • Implement history of short links,
  • Add rate limiting to prevent DoS attacks and brute-forcing.

Deployment

docker run -d --restart unless-stopped --name links -p 8080:8080 -v /var/links:/app-storage ghcr.io/jakubbizewski/jakubme_links:master

Endpoints

Create Short Link

POST /new
{
  "targetUrl": "https://www.google.com"
}

Response:
200 OK
{
  "shortLink": "abc123"
}


400 Bad Request
{
  "error": "Invalid URL"
}

Use Short Link

GET /abc123

Response:
302 Found
Location: https://www.google.com

Project Structure

  • adapters/: Contains the web interface and memory repository implementations.
  • domain/: Contains the domain model and ports for the application.
  • mocks/: Contains mock implementations for testing.
  • main.go: The entry point for the application.

Running the Application

To run the application, use the following command:

go run main.go

Testing

go test ./...

bizewskime_links's People

Contributors

dependabot[bot] avatar jakubbizewski avatar

Watchers

 avatar

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.