A high-performance URL shortener built with modern Go technologies, providing URL shortening, redirection, and tracking features. This project uses Go's powerful libraries.
- Generate short URLs for long links.
- Redirect users to the original URL using the shortened link.
- Persistent storage for URL mappings.
- Built-in observability for tracing and monitoring.
- Unit testing for robust code quality.
- Echo: Web framework for building RESTful APIs.
- Cobra: CMD runner
- GORM: ORM library for database management.
- Viper: Configuration management.
- Testify: Unit testing and mocking.
- Jaeger: Distributed tracing.
- OpenTelemetry: Observability and monitoring.
Ensure you have the following installed:
-
Clone the repository:
git clone https://github.com/memariyan/url-shortener.git cd url-shortener -
Install dependencies:
go mod tidy
-
Run the application:
cd ./docker sh start-services.sh
The project uses Viper for managing configurations. Configuration values can be set in the config.yaml file or via environment variables.
Example config.yaml:
server:
address: "http://localhost"
port: 8001
mysql:
host: "mysql"
port: 3306
username: "root"
password: "root"
db: "url_shortener"
redis:
host: "redis"
port: 6379
jaeger:
host: "jaeger"
port: 4318
worker:
size: 10| Method | Endpoint | Description |
|---|---|---|
| POST | /convert |
Create a new short URL. |
| GET | /:shortURL |
Redirect to the original URL |
| GET | /metrics |
Check service metrics. |
The project uses Testify for unit testing. Run the tests with:
go test ./...-
Access the Jaeger UI at http://localhost:16686.
-
The service automatically sends traces to the Jaeger endpoint specified in
config.yaml.
-
Access the Grafana UI at http://localhost:3003.
-
You can see all metrics has been exposed by application in /metrics endpoint