This is a simple URL shortener service built using Go. It provides basic functionality for creating short links, redirecting to the original links, and hosting a main webpage.
This is my first project in Go, so I'm open to any constructive feedback or suggestions. 😊
- POST
/: Creates a new shortened link. - GET
/: Serves the main web page. - GET
/<code>: Redirects to the original URL associated with the provided code.
Make sure you have Go installed on your system. You can verify this by running:
go versionIf Go is not installed, follow the official installation guide.
If you do not already have a PostgreSQL database configured, you can set one up using Docker:
Run the following command to create a PostgreSQL container:
docker run --name postgres-shortener -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=shorter -p 5432:5432 -d postgresThis will:
- Set the PostgreSQL username to
postgres. - Set the password to
password. - Create a database named
shorter. - Expose the database on port
5432.
Ensure the file config/ConnectDB.go has the following settings:
const (
host = "localhost" // Replace with your database host, e.g., localhost if Docker is local
port = "5432"
user = "postgres"
password = "password"
dbname = "shorter"
)If the database is not running on the same machine as the service, replace localhost in the host variable with the appropriate IP address of your database server.
Run the following command to install all required Go modules:
go mod tidyRun the service with:
go run main.goThe service will now be running and available at http://localhost:8080 by default.
- If you're running the service behind a proxy, ensure that ports are forwarded correctly.
- This project is designed to be lightweight and simple, so additional features can be added as needed.
- Constructive feedback and suggestions are highly appreciated!
Thank you for checking out my project! 🎉