A minimal self-hosted paste sharing app built with Go, PostgreSQL, and a lightweight web UI.
- Features
- Tech Stack
- Project Structure
- Screenshots
- Getting Started
- Run with Docker (Recommended)
- Run Locally
- Environment Variables
- API Reference
- Makefile Commands
- Troubleshooting
- Contributing
- Create sharable paste links with short IDs
- Fetch existing pastes by ID
- Stores paste content in PostgreSQL
- Serves frontend and API from one Go service
- Dockerized app + database setup
- Makefile-based developer workflow
- Backend: Go 1.22
- Router: gorilla/mux
- Database: PostgreSQL
- Frontend: HTML, JavaScript, Tailwind CSS, highlight.js
- Containerization: Docker, Docker Compose
.
├── cmd/ # App entrypoint and HTTP server
├── service/ # Route handlers and DB store
├── generator/ # Short ID generation logic
├── templates/ # Frontend static assets
├── Dockerfile
├── docker-compose.yml
├── Makefile
└── .env.example
- Go 1.22+
- Docker + Docker Compose (for containerized run)
- Make
- Copy environment template:
cp .env.example .env- Start services:
make docker-up- Open app in browser:
http://localhost:5001
- Watch logs:
make docker-logs- Stop services:
make docker-downmake docker-up APP_PORT=8080Then open:
http://localhost:8080
- Start PostgreSQL locally (or keep DB running in Docker).
- Copy and edit environment file:
cp .env.example .env- Install dependencies and run:
make deps
make runDefault local address:
http://localhost:5000
| Variable | Default | Description |
|---|---|---|
| SERVER_ADDR | :5000 | Server bind address inside app |
| DB_HOST | localhost | PostgreSQL host (use db in Docker network) |
| DB_PORT | 5432 | PostgreSQL port |
| DB_USER | pastebin | PostgreSQL username |
| DB_PASSWORD | pastebin | PostgreSQL password |
| DB_NAME | pastebin | PostgreSQL database name |
| APP_PORT | 5001 | Host port mapped to container port 5000 (Docker only) |
Base path:
/api/v1
POST /api/v1/
Request body:
{
"content": "package main\nfunc main(){}"
}Response:
{
"id": "abc123"
}GET /api/v1/{id}
Response:
{
"id": 1,
"uid": "abc123",
"content": "package main\nfunc main(){}"
}curl -X POST http://localhost:5001/api/v1/ \
-H "Content-Type: application/json" \
-d '{"content":"hello from pastebin"}'
curl http://localhost:5001/api/v1/<PASTE_ID>make help # List all targets
make deps # Download Go modules
make build # Build binary in ./bin
make run # Run app locally
make test # Run tests
make fmt # Format Go files
make vet # Run go vet
make clean # Remove local build artifacts
make docker-build # Build Docker images
make docker-up # Start app + db (detached)
make docker-down # Stop and remove compose services
make docker-logs # Tail container logs
make docker-ps # Show compose container status
make docker-restart# Restart servicesIf startup fails due to port conflicts, run with a different host port:
make docker-up APP_PORT=8080- Ensure
dbservice is healthy:
make docker-ps- Check logs:
make docker-logs- Fork the repository
- Create a feature branch
- Commit your changes
- Open a pull request
If you want, I can also add a LICENSE, CI workflow, and badges to make this repo even more open-source ready.


