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.
- Create and store text/code snippets
- View individual snippets via unique URLs
- Simple and intuitive API for snippet management
- Go (v1.16 or higher)
- MySQL (or access to a managed MySQL instance like Aiven)
.
├── certificates
├── cmd
│ └── web
├── internal
│ ├── models
│ └── validator
├── tls
└── ui
├── html
│ ├── pages
│ └── partials
└── static
├── css
├── img
└── js
-
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
- Configure the database:
- Set up your MySQL connection details in cmd/web/main.go (or via environment variables).
-
Run the application:
go run ./cmd/web
- The app will start on http://localhost:4000
- 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" }
- View A Snippet:
-
Method GET
http://localhost:4000/snippet/view/2 -
Example:
GET http://localhost:4000/snippet/view/2
- View List of all Snippets:
-
Method GET
http://localhost:4000
This project is deployed on Render for easy access
This project is open-source and available under the MIT License.
🛠 🚧 under construction 😐