A simple URL shortener service built with Go using only the standard library.
- Go 1.21 or higher
- Make (optional, for using Makefile commands)
.
├── cmd/
│ └── server/
│ └── main.go
├── internal/
│ ├── handlers/
│ │ └── handlers.go
│ └── middleware/
│ └── middleware.go
├── Makefile
├── go.mod
└── README.md
- Clone the repository:
git clone https://github.com/AjayPoshak/url-shortener.git
cd url-shortener
- Install dependencies:
go mod tidy
There are several ways to run the server:
go run cmd/server/main.go
# Run the server
make run
# Build the binary
make build
# Clean build artifacts
make clean
podman compose watch
The server will start on http://localhost:8095
You can test the endpoints using curl:
# Test home endpoint
curl http://localhost:8095/
# Test health endpoint
curl http://localhost:8095/health
cmd/server/main.go
- Main application entry pointinternal/handlers/
- HTTP request handlersinternal/middleware/
- HTTP middleware (logging, etc.)
mongosh -u admin -p --authenticationDatabase admin
curl -v -H "Content-Type: application/json" -H "Authorization: Basic $(echo -n username:password | base64)" -d '{"URL": "https://example.com/1", "userId": 1}' https://urlly.app/urls
To build a production binary:
go build -ldflags="-w -s" -o url-shortener cmd/server/main.go
The binary will be created in the current directory and can be run with:
./url-shortener
- Fork the repository
- Create your feature branch (
git checkout -b feature/awesome-feature
) - Commit your changes (
git commit -m 'Add awesome feature'
) - Push to the branch (
git push origin feature/awesome-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.