8000 GitHub - emiliogain/snippetbox
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

emiliogain/snippetbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SnippetBox

SnippetBox is a web application written in Go that allows users to paste and share snippets of text. This project demonstrates various web development techniques and features including RESTful routing, middleware usage, dynamic HTML generation, MySQL database integration, stateful HTTP sessions, and secure user authentication.

image

Features

  • RESTful Routing: Clean and organized URL routes that follow REST principles.
  • Middleware: Middleware for request logging, secure headers, and more.
  • Dynamic HTML: Server-side rendering of HTML templates.
  • MySQL Database: Persistent storage of snippets and user data using MySQL.
  • Sessions: Stateful HTTP sessions for maintaining user state across requests.
  • Secure User Authentication: User authentication with password hashing and secure session management.

Getting Started

Prerequisites

  • Go 1.16+
  • MySQL 5.7+

Installation

  1. Clone the repository:
    git clone https://github.com/emiliogain/snippetbox.git
    cd snippetbox
    
  2. Set up the MySQL database:
     CREATE DATABASE snippetbox;
     USE snippetbox;
    
     CREATE TABLE users (
     id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
     name VARCHAR(255) NOT NULL,
     email VARCHAR(255) NOT NULL,
     hashed_password CHAR(60) NOT NULL,
     created DATETIME NOT NULL,
     active BOOLEAN NOT NULL DEFAULT TRUE
     );
     ALTER TABLE users ADD CONSTRAINT users_uc_email UNIQUE (email);
    
     CREATE TABLE snippets (
     id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
     title VARCHAR(100) NOT NULL,
     content TEXT NOT NULL,
     created DATETIME NOT NULL,
     expires DATETIME NOT NULL
     );
     CREATE INDEX idx_snippets_created ON snippets(created);
    
  3. Run the application:
    go run ./cmd/web
    
  4. Visit http://localhost:4000 in your web browser to use the application.

Usage

  • Create a Snippet:
    1. Click the "Create Snippet" button on the homepage.
    2. Write a title and content for your snippet.
    3. Choose an expiration time: 1 year, 1 week, or 1 day.
    4. Click the "Publish Snippet" button to save and share your snippet.

image image

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Alex Edwards for his book "Let’s Go", which inspired this project.
  • The Go community for providing extensive libraries and tools.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0