Skip to content

This application lets people paste and share snippets of text and code — a bit like Pastebin or GitHub’s Gists. **Please wait for render to warm up the server instances when launching the application link

MlondiMchunu/snippetbox

Repository files navigation

SnippetBox - A Text and Code Snippet Sharing Application

SnippetBox is a lightweight web application that allows users to paste and share snippets of text and code, similar to Pastebin or GitHub's Gists. It uses a managed MySQL database hosted on Aiven and is built with Go.

Features

  • Create and store text/code snippets
  • View individual snippets via unique URLs
  • Simple and intuitive API for snippet management

Getting Started

Prerequisites
  • Go (v1.16 or higher)
  • MySQL (or access to a managed MySQL instance like Aiven)
Project Structure
  .
  ├── certificates
  ├── cmd
  │   └── web
  ├── internal
  │   ├── models
  │   └── validator
  ├── tls
  └── ui
      ├── html
      │   ├── pages
      │   └── partials
      └── static
          ├── css
          ├── img
          └── js
Installation
  1. Clone the repository:

     git clone https://www.github.com/MlondiMchunu/snippetbox.git
     cd snippetbox
    

1.1 Run from Docker:

  # Build the image
  ocker build -t snippetbox .

  # Run the container
  docker run -p 4000:4000 -p 443:443 snippetbox

  # Or with compose
  docker-compose up -d
  1. Configure the database:
  • Set up your MySQL connection details in cmd/web/main.go (or via environment variables).
  1. Run the application:

     go run ./cmd/web  
    
API Endpoints:
  1. Create a Snippet:
  • Method POST

    http://localhost:4000/snippet/create
    
  • Request Body:

    {  
      "title": "Example Snippet",  
      "content": "This is a test snippet.",  
      "expires": "24h"  // Optional: "1h", "24h", "7d", or "never"  
    }  
    
  1. View A Snippet:
  • Method GET

    http://localhost:4000/snippet/view/2
    
  • Example:

    GET http://localhost:4000/snippet/view/2  
    
  1. View List of all Snippets:
  • Method GET

     http://localhost:4000
    
Deployment

This project is deployed on Render for easy access

License

This project is open-source and available under the MIT License.

image

🛠 🚧 under construction 😐

About

This application lets people paste and share snippets of text and code — a bit like Pastebin or GitHub’s Gists. **Please wait for render to warm up the server instances when launching the application link

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published