This project is a simple URL shortener written in Go and uses the Chi library for handling HTTP requests. It allows you to create short aliases for long URLs and perform redirection from the short alias to the original URL.
-
Install Go if you haven't already. You can download it from the official website.
-
Clone the repository:
git clone https://github.com/RomanVassilchenko/simple-url-shortener.git
-
Change to the project directory:
cd simple-url-shortener
-
Install dependencies:
go mod download
⚠️ Don't forget to add CONFIG_PATH to your env like this:export CONFIG_PATH=./config/local.yaml
-
Build and Run the project:
go build -o simple-url-shortener ./cmd/simple-url-shortener
The application should be accessible at http://localhost:8082
.
To create a short alias for a URL, send a POST request to /
with a JSON body in the following format:
{
"alias": "myalias",
"url": "https://example.com/long-url"
}
To get a redirection to the original URL, send a GET request to /alias, where alias is the short alias you created earlier. The application will perform a redirect to the corresponding URL.
To delete an alias from the database, send a DELETE request to /myalias
, where myalias is the alias you want to delete.
The application uses an SQLite database to store aliases and their corresponding URLs. The database is created automatically on the first run of the application.
This project uses the following libraries:
Chi - HTTP request routing.
This project is licensed under the MIT License. See the LICENSE file for details.
Author: Roman Vassilchenko