Skip to content

farpat/go-url-shortener

Repository files navigation

This project is a simple URL shortener written in Go. Test

This is the structure of the project:

├── certs                         => Certificate files (generated by make update-certificates)
├── cmd
│   ├── server
│   │   └── main.go               => Main application
│   └── tools                     => Folder containing command line tools
│       ├── {command}/main.go
│       └── ...
├── internal
│   ├── config                    => Configuration files
│   ├── errors                    => Custom errors
│   ├── handlers                  => Handlers for API endpoints
│   ├── middlewares               => HTTP Middlewares
│   ├── models                    => Database models
│   ├── repositories              => Database repositories
│   ├── services                  => Business logic
│   ├── utils                     => Utility functions
│   └── validation                => Contains custom validation rules
│       ├── main.go               => Validation rules
│       └── rule-{rule-name}.go   => Custom validation rule
├── tests
│   ├── unit                      => Unit tests
│   └── feature                   => Tests of endpoints or commands (cmd/tools)
├── .air.toml                     => Auto-reload configuration
└── Makefile                      => Developer commands

API

Note

Note that Urls.postman_collection.json contains all exported endpoints from Postman.

Login

POST /oauth/login

List all short URLs

GET /api/urls

Get a short URL by slug

GET /api/urls/{slug}

Create a new short URL

POST /api/urls
{
    "url": "https://example.com"
}

Delete a short URL

DELETE /api/urls/{slug}

Installation

git clone https://github.com/farpat/go-url-shortener.git
cd go-url-shortener
cp .env.example .env
make install

Usage

make update-certificates
make run

and watch the instructions.

If you want to debug the application with VSCode, you can use the following configuration .vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug main.go (public)",
      "type": "go",
      "request": "launch",
      "mode": "debug",
      "program": "${workspaceFolder}/cmd/server/main.go",
      "envFile": "${workspaceFolder}/.env"
    }
  ]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published