Skip to content

Repository files navigation

Pastebin

A minimal self-hosted paste sharing app built with Go, PostgreSQL, and a lightweight web UI.

Table of Contents

Features

  • 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

Tech Stack

  • Backend: Go 1.22
  • Router: gorilla/mux
  • Database: PostgreSQL
  • Frontend: HTML, JavaScript, Tailwind CSS, highlight.js
  • Containerization: Docker, Docker Compose

Project Structure

.
├── 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

Screenshots

Home

Home screen

URL CHANGE VIEW

Paste view

SAVED PREVIEW

UI preview

Getting Started

Prerequisites

  • Go 1.22+
  • Docker + Docker Compose (for containerized run)
  • Make

Run with Docker (Recommended)

  1. Copy environment template:
cp .env.example .env
  1. Start services:
make docker-up
  1. Open app in browser:
http://localhost:5001
  1. Watch logs:
make docker-logs
  1. Stop services:
make docker-down

Custom app port

make docker-up APP_PORT=8080

Then open:

http://localhost:8080

Run Locally

  1. Start PostgreSQL locally (or keep DB running in Docker).
  2. Copy and edit environment file:
cp .env.example .env
  1. Install dependencies and run:
make deps
make run

Default local address:

http://localhost:5000

Environment Variables

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)

API Reference

Base path:

/api/v1

Create paste

POST /api/v1/

Request body:

{
  "content": "package main\nfunc main(){}"
}

Response:

{
  "id": "abc123"
}

Get paste by ID

GET /api/v1/{id}

Response:

{
  "id": 1,
  "uid": "abc123",
  "content": "package main\nfunc main(){}"
}

Quick curl examples

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>

Makefile Commands

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 services

Troubleshooting

Port already in use

If startup fails due to port conflicts, run with a different host port:

make docker-up APP_PORT=8080

Could not connect to database

  • Ensure db service is healthy:
make docker-ps
  • Check logs:
make docker-logs

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. 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.

About

Pastebin is a simple tool for sharing and storing code snippets. Create, share, and access your pastes anytime, anywhere.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages