Skip to content

ehz0ah/GoGin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Events API – Go & Gin (Learning Project)

A RESTful API for event management, built with Go and the Gin framework. This project demonstrates secure authentication, CRUD operations, and relational data modeling using SQLite. It was developed as a learning exercise to explore backend development in Go.


Overview

This API allows users to:

  • Register and authenticate with hashed passwords
  • Create, view, update, and delete events
  • Register for and cancel event participation
  • Interact with a persistent SQLite database

Authentication is handled via JWT tokens. All sensitive operations require a valid token.


Features

  • User Management: Signup and login with secure password hashing (bcrypt)
  • Authentication: JWT-based stateless authentication
  • Event Management: Full CRUD for events
  • Registration: Users can register for or cancel event participation
  • Persistence: SQLite database with automatic table creation
  • Authorization: Middleware to protect sensitive routes

Project Structure

  • Entry Point: app.go – Initializes the database and registers routes
  • Models: models/ – Data models for users and events
  • Routes: routes/ – HTTP handlers for users, events, and registrations
  • Middleware: middlewares/auth.go – JWT authentication
  • Utilities: utils/ – Password hashing and JWT helpers
  • Sample Requests: api-test/ – Example HTTP requests for testing

Technology Stack

  • Go 1.21+
  • Gin Web Framework
  • SQLite
  • JWT (github.com/golang-jwt/jwt/v5)
  • bcrypt (golang.org/x/crypto/bcrypt)

Getting Started

  1. Clone the repository
  2. Install dependencies
    go mod tidy
    
  3. Run the application
    go run app.go
    
  4. The API will be available at http://localhost:8080

A new api.db SQLite database will be created automatically.


Authentication Flow

  1. Signup: POST /signup
    Create a new user account.
  2. Login: POST /login
    Obtain a JWT token.
  3. Authenticated Requests:
    Include the token in the Authorization header (no "Bearer" prefix).

API Endpoints

Public:

  • GET /events – List all events
  • GET /events/:id – Get event details
  • POST /signup – Register a new user
  • POST /login – Authenticate and receive a JWT

Authenticated (JWT required):

  • POST /events – Create an event
  • PUT /events/:id – Update an event (creator only)
  • DELETE /events/:id – Delete an event (creator only)
  • POST /events/:id/register – Register for an event
  • DELETE /events/:id/register – Cancel registration

Example: Creating an Event

POST /events
Authorization: <token>
Content-Type: application/json

{
  "name": "Sample Event",
  "description": "A demonstration event.",
  "location": "Online",
  "dateTime": "2025-01-01T15:30:00Z"
}

See api-test/ for more examples.


Notes

  • The JWT secret is hard-coded for demonstration purposes only.
  • The Authorization header expects the raw token (no "Bearer" prefix).
  • This project is intended for educational use and is not production-ready.

About

Events API with Go + Gin + JWT + SQLite

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages