A modern code snippet sharing platform with syntax highlighting and expirable pastes. Built with Next.js frontend and Go backend.
PasteCTL Web is a lightweight pastebin alternative that allows developers to share code snippets quickly and securely. Each paste can be configured with custom expiry times and supports syntax highlighting for multiple programming languages.
- Syntax Highlighting: Support for multiple programming languages with automatic syntax detection
- Custom Expiry Times: Set pastes to expire after 1 hour, 24 hours, or custom durations
- Live Editing: Real-time collaborative editing using WebSocket connections
- View Tracking: Monitor paste view counts
- Raw Content Access: Retrieve paste content in raw format via API
- CLI Integration: Access and manage pastes from the command line using PasteCTL CLI
- Automatic Cleanup: Scheduled job to delete expired pastes
- Framework: Next.js with React
- Styling: Tailwind CSS
- Deployment: AWS Amplify
- Live URL: paste.sumedh.app
- Language: Go 1.24.0
- Framework: Gin Web Framework
- Database: PostgreSQL (via pgx driver)
- WebSocket: Gorilla WebSocket for live editing
- Deployment: AWS EC2
- Testing: Testcontainers for integration tests
- Gin: Web framework with CORS support
- pgx/v5: PostgreSQL driver and toolkit
- Gorilla WebSocket: WebSocket implementation
- godotenv: Environment variable management
- Testcontainers: Testing with containerized PostgreSQL
- Go 1.24.0 or higher
- PostgreSQL database
- Node.js 18+ (for frontend)
- Clone the repository:
git clone https://github.com/sumedhvats/pastectl_web.git
cd pastectl_web- Install dependencies:
go mod download- Configure environment variables:
Create a
.envfile in the root directory:
DATABASE_URL=postgresql://user:password@localhost:5432/pastes
FRONTEND_URL=http://localhost:3000- Run the server:
go run main.goThe backend server will start on http://localhost:8080
- Navigate to the frontend directory:
cd frontend- Install dependencies:
npm install- Run the development server:
npm run devThe frontend will be available at http://localhost:3000
POST /api/pastes- Create a new pasteGET /api/pastes/:id- Get paste by IDGET /api/pastes/:id/raw- Get raw paste contentPUT /api/pastes/:id- Update existing pastePUT /api/pastes/:id/view- Increment view count
GET /api/ws/:id- WebSocket endpoint for live editing
The application uses PostgreSQL with the following main table structure:
CREATE TABLE pastes (
id VARCHAR PRIMARY KEY,
content TEXT NOT NULL,
language VARCHAR NOT NULL,
expire_at TIMESTAMP,
views INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT NOW()
);The project includes comprehensive test coverage:
# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run specific test suite
go test ./internal/db/...
go test ./internal/http/...
go test ./internal/paste/...- Database Tests: Integration tests using Testcontainers with PostgreSQL
- HTTP Handler Tests: Unit tests with mocked services
- Service Tests: Integration tests for business logic
pastectl_web/
├── cmd/
│ └── scheduledJob/ # Background job for cleanup
├── internal/
│ ├── db/ # Database layer
│ ├── http/ # HTTP handlers
│ ├── paste/ # Business logic
│ └── ws/ # WebSocket handlers
├── migrations/ # Database migrations
├── tests/ # Test suites
│ ├── db_test/
│ ├── http_test/
│ └── service_test/
├── frontend/ # Next.js application
│ ├── app/
│ │ └── paste/
│ ├── components/
│ └── public/
├── main.go
└── go.mod
PasteCTL includes a dedicated command-line interface for terminal users. Visit the PasteCTL CLI repository for installation and usage instructions.
The Go backend is deployed on AWS EC2 with the following configuration:
- PostgreSQL database
- Environment variables configured via
.env - CORS enabled for frontend domain
The Next.js frontend is deployed on AWS Amplify with automatic deployments on push to main branch.
| Variable | Description | Required |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string | Yes |
FRONTEND_URL |
Frontend application URL for CORS | Yes |
Configuration is handled through Next.js environment variables (refer to frontend documentation).
The application includes a background scheduler that runs periodic tasks:
- Expired Paste Cleanup: Automatically deletes pastes that have exceeded their expiry time
- CORS configuration for cross-origin requests
- Input validation on all endpoints
- SQL injection prevention via parameterized queries
- Automatic expiry of sensitive content
- Connection pooling for database operations
- Efficient WebSocket connections for live editing
- Automatic cleanup to prevent database bloat
Backend:
go run main.goFrontend:
cd frontend
npm run devThe project follows Go best practices:
- Proper error handling
- Interface-based design for testability
- Dependency injection
- Comprehensive test coverage
- PasteCTL CLI - Command-line interface for PasteCTL
For issues, questions, or contributions, please visit the GitHub Issues page.
Made with ❤️ for the developer community..