A specialized URL shortener service that only accepts and processes marketplace URLs. Built with Go, MySQL, and Redis.
Production live: acheisuacara.com.br
- URL shortening for marketplace links only
- Rate limiting (60 requests per minute)
- Click tracking
- Input validation
- Duplicate URL detection
- Permanent redirects
- Amazon
- MercadoLivre
- Americanas
- Magazine Luiza
- Shopee
- AliExpress
- Go 1.16 or higher
- MySQL 8 or higher ( i am using an external mysql xd )
- Redis 6.0 or higher
- Clone the repository:
git clone https://github.com/yourusername/acheisuacara.com.br.git
cd acheisuacara.com.br
- Install dependencies:
go mod download
- Configure the application:
- Copy
.env.example
to the root directory and fill with your values - Update the configuration values as needed
- Create the MySQL database:
CREATE DATABASE acheisuacara;
- Run the application:
go run cmd/api/main.go
The project uses SQLite for testing to avoid requiring a MySQL database during tests. To run the tests:
- Run all tests:
go test ./... -v
- Run tests for specific packages:
# Test models
go test ./pkg/models -v
# Test services
go test ./pkg/services -v
# Test handlers
go test ./pkg/handlers -v
- Run tests with coverage:
go test ./... -v -cover
- Run tests and generate coverage report:
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
Note: The "record not found" messages during tests are expected and part of the test cases.
POST /api/shorten
Content-Type: application/json
{
"url": "https://www.amazon.com/product/123"
}
GET /:shortCode
The API is rate-limited to 60 requests per minute per IP address. If you exceed this limit, you'll receive a 429 Too Many Requests response.
- 400 Bad Request: Invalid URL or non-marketplace URL
- 404 Not Found: Short URL not found
- 429 Too Many Requests: Rate limit exceeded
- 500 Internal Server Error: Server-side error
MIT License