Shortener is a simple URL shortening service written in Go. It provides the ability to create short, memorable links that redirect to longer URLs.
To run Shortener, ensure you have the following installed:
- Go (version 1.21 or newer)
- Docker (optional)
The application also requires access to a database. The provided schema.sql
file includes the SQL schema that is compatible with MySQL.
- Navigate to the
shortener
directory. - Run the Go build command:
go build -o shortener ./cmd/shortener
- The
shortener
binary will be created in the current directory.
- Navigate to the root directory of the project.
- Build the Docker image with the following command:
docker build -t shortener -f deployment/Dockerfile .
- The Docker image tagged as
shortener
will be created.
The application can be configured using the yaml
files located in the deployment/configs/
directory. It supports environment-specific configurations:
prod.yaml
for productiontest.yaml
for testingdev.yaml
for developmentlocal.yaml
for local development
Adjust the configurations as needed for your environment, such as database credentials, datastore identifiers, or cache settings.
Execute the built binary with the following command:
./shortener
You can set the ENV
environment variable to load specific configurations:
ENV=local ./shortener
- Run the Docker image with the following command:
docker run -p 8080:8080 -e ENV=local shortener
- The application will be accessible on port
8080
.
Refer to the provided Dockerfile
in deployment/
directory for deployment configurations. Update it as necessary to use your base image and desired environment.
To set up your database, use the schema.sql
file located in the deployment/
directory. This file contains the SQL commands to create the necessary tables and sample data.
This project is licensed under the MIT License. See the LICENSE
file for details.