Categorygithub.com/mujeebcodes/snippetbox
module
0.0.0-20241207212859-b1d5198b8887
Repository: https://github.com/mujeebcodes/snippetbox.git
Documentation: pkg.go.dev

# README

Snippetbox šŸ“œ

Snippetbox is a web application for pasting and sharing snippets of text, inspired by tools like Pastebin and GitHub Gists. Built step-by-step using the Go programming language, this project follows the tutorial in the book Let's Go by Alex Edwards.

Features ✨

  • View and create text snippets.
  • User authentication and session management.
  • Secure server configuration with HTTPS.
  • Dynamic HTML templating and inheritance.
  • Middleware for enhanced functionality.
  • A MySQL database for storing snippets.

Project Structure šŸ“‚

The project follows a modular structure for scalability and maintainability:

.
ā”œā”€ā”€ cmd
│   └── web            # Main application entry point and handlers
│       ā”œā”€ā”€ context.go       # Context-related logic
│       ā”œā”€ā”€ handlers.go      # HTTP handlers
│       ā”œā”€ā”€ helpers.go       # Utility functions
│       ā”œā”€ā”€ main.go          # Application entry point
│       ā”œā”€ā”€ middleware.go    # Middleware for HTTP requests
│       ā”œā”€ā”€ routes.go        # HTTP route configurations
│       └── templates.go     # HTML template helpers
ā”œā”€ā”€ internal
│   ā”œā”€ā”€ models         # Database models and related logic
│   │   ā”œā”€ā”€ errors.go        # Custom error definitions
│   │   ā”œā”€ā”€ snippets.go      # Snippet model and queries
│   │   └── users.go         # User model and queries
│   └── validator      # Input validation logic
│       └── validator.go     # Validators for user input
ā”œā”€ā”€ tls                # TLS certificates for HTTPS
│   ā”œā”€ā”€ cert.pem            # Public certificate
│   └── key.pem             # Private key
ā”œā”€ā”€ ui
│   ā”œā”€ā”€ html           # HTML templates for the application
│   │   ā”œā”€ā”€ pages            # Individual pages
│   │   │   ā”œā”€ā”€ create.tmpl.html
│   │   │   ā”œā”€ā”€ home.tmpl.html
│   │   │   ā”œā”€ā”€ login.tmpl.html
│   │   │   ā”œā”€ā”€ signup.tmpl.html
│   │   │   └── view.tmpl.html
│   │   └── partials         # Reusable components
│   │       ā”œā”€ā”€ base.tmpl.html
│   │       └── nav.tmpl.html
│   └── static         # Static assets (CSS, JS, images)
│       ā”œā”€ā”€ css
│       ā”œā”€ā”€ img
│       └── js
ā”œā”€ā”€ efs.go             # Entry point for embedded file system
└── .gitignore         # Git ignore file

Getting Started šŸš€

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/mujeebcodes/snippetbox.git
    cd snippetbox
    
  2. Install Go dependencies:

    go mod tidy
    
  3. Set up the MySQL database:

    • Create a database named snippetbox.
    • Run the SQL schema provided in internal/models/schema.sql.
  4. Start the application:

    go run ./cmd/web
    
  5. Access the application at http://localhost:4000.

Configuration

Environment variables:

  • DSN: Data Source Name for connecting to the MySQL database (e.g., user:password@/snippetbox).

Development šŸ› ļø

Running Tests

Unit and integration tests can be run using:

go test ./...

Directory for Templates

HTML templates are located in the ui/html directory, and you can customize them to change the appearance of the application.

Contributions šŸ¤

Contributions are welcome! Feel free to open an issue or submit a pull request.

Acknowledgments šŸ™

This project is built as a part of the tutorial in the book Let's Go by Alex Edwards.

License šŸ“

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

# Packages

No description provided by the author
No description provided by the author