This project is a simple URL shortener written in Go.
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
Note
Note that Urls.postman_collection.json contains all exported endpoints from Postman.
POST /oauth/loginGET /api/urlsGET /api/urls/{slug}POST /api/urls
{
"url": "https://example.com"
}DELETE /api/urls/{slug}git clone https://github.com/farpat/go-url-shortener.git
cd go-url-shortener
cp .env.example .env
make installmake update-certificates
make runand 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"
}
]
}