Snippetbox - A Golang Web Application
Welcome to Snippetbox, a web application for storing and managing snippets of text. This project is built as part of my journey to learn web development in Go (Golang), based on the book Let's Go! by Alex Edwards.
π Project Overview
Snippetbox is a simple yet powerful web application that allows users to:
- Create snippets of text.
- View snippets by their unique ID.
- Browse a list of the latest snippets.
This project is a learning exercise designed to implement the best practices in Go web development, including working with templates, routing, forms, authentication, and more.
π Features
- Fast and Efficient: Built using Go, a statically-typed, compiled language optimized for performance.
- Clean Architecture: Implements the layered design principles from Let's Go!
- HTML Templates: Dynamically render web pages using Go's
html/template package.
- Secure: Includes best practices for input validation and protection against common vulnerabilities like XSS.
- MySQL Integration: Uses MySQL as the database to store snippet information.
π What I Learned
While building this project, I focused on:
- Structuring a Go web application for maintainability and scalability.
- Using Go's built-in libraries for routing and templating.
- Handling forms and managing user input securely.
- Working with a database (MySQL) in Go.
- Adding session-based authentication.
π§ Getting Started
Prerequisites
Installation
-
Clone the repository:
git clone https://github.com/Turtel216/snippetbox.git
cd snippetbox
-
Install dependencies:
go mod tidy
-
Set up Docker:
docker-compose up --build
-
Open your browser and visit: http://localhost:4000
π Project Structure
snippetbox/
βββ cmd/
β βββ web/ # Entry point for the application
βββ internal/
β βββ models/ # Database models and queries
β βββ handlers/ # HTTP handlers for routing
β βββ validation/ # Form validation helpers
β βββ β¦
βββ init-scripts/ # Database schema and migrations
βββ go.mod # Dependencies file
βββ Dockerfile # Snippetbox docker container
βββ docker-compose.yml # Data base and web app config
βββ README.md # Project documentation
π€ Contributing
Contributions are welcome! Feel free to submit issues or pull requests to improve this project.
π License
This project is for educational purposes and is not intended for production use.
π Acknowledgments
- Special thanks to Alex Edwards for writing Let's Go!, which served as the primary resource for this project.