Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go REST API - Event Management System

A RESTful API built with Go and the Gin framework for managing events and user registrations. This project demonstrates a complete backend implementation with authentication, database management, and CRUD operations.

Features

  • User Authentication

    • User signup and login
    • Password hashing with bcrypt
    • JWT-based authentication
    • Protected routes with authentication middleware
  • Event Management

    • Create, read, update, and delete events
    • Event details including name, description, location, and date/time
    • User ownership of events
  • Event Registration

    • Users can register for events
    • Cancel event registrations
    • Track event attendees

Tech Stack

  • Language: Go 1.21.2
  • Web Framework: Gin
  • Database: SQLite3
  • Authentication: JWT (JSON Web Tokens)
  • Password Hashing: bcrypt

Project Structure

.
├── main.go              # Application entry point
├── db/                  # Database initialization and configuration
│   └── db.go
├── models/              # Data models
│   ├── event.go         # Event model and database operations
│   └── user.go          # User model and authentication
├── routes/              # Route handlers
│   ├── routes.go        # Route registration
│   ├── events.go        # Event-related endpoints
│   ├── users.go         # User authentication endpoints
│   └── register.go      # Event registration endpoints
├── middlewares/         # HTTP middlewares
│   └── auth.go          # JWT authentication middleware
├── utils/               # Utility functions
│   ├── hash.go          # Password hashing utilities
│   └── jwt.go           # JWT token generation and validation
└── api-test/            # HTTP request examples for testing

Prerequisites

  • Go 1.21.2 or higher
  • SQLite3

Installation & Setup

  1. Clone the repository

    git clone https://github.com/adhirajkar/events-rest-api.git
    cd events-rest-api
  2. Install dependencies

    go mod download
  3. Run the application

    go run main.go

    The server will start on http://localhost:8080

  4. Database

    • The SQLite database (api.db) will be created automatically on first run
    • Tables are created automatically via migrations in db/db.go

API Endpoints

Authentication

Signup

POST /signup
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "yourpassword"
}

Login

POST /login
Content-Type: application/json

{
  "email": "user@example.com",
  "password": "yourpassword"
}

Events (Public)

Get All Events

GET /events

Get Single Event

GET /events/:id

Events (Protected - Requires Authentication)

Add the JWT token from login response to the Authorization header:

Create Event

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

{
  "name": "Tech Conference 2025",
  "description": "Annual technology conference",
  "location": "San Francisco, CA",
  "dateTime": "2025-06-15T09:00:00.000Z"
}

Update Event

PUT /events/:id
Authorization: <jwt-token>
Content-Type: application/json

{
  "name": "Updated Event Name",
  "description": "Updated description",
  "location": "New Location",
  "dateTime": "2025-06-16T10:00:00.000Z"
}

Delete Event

DELETE /events/:id
Authorization: <jwt-token>

Event Registration (Protected)

Register for Event

POST /events/:id/register
Authorization: <jwt-token>

Cancel Registration

DELETE /events/:id/register
Authorization: <jwt-token>

Testing

The api-test/ directory contains HTTP request files for testing all endpoints. You can use these with:

  • REST Client VS Code extension
  • Any HTTP client (Postman, Insomnia, etc.)

Example test files:

  • create-user.http - User signup
  • login.http - User login
  • get-events.http - Fetch all events
  • create-event.http - Create new event
  • update-event.http - Update existing event
  • delete-event.http - Delete event
  • register.http - Register for event
  • cancel-registration.http - Cancel event registration

Database Schema

Users Table

CREATE TABLE users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    email TEXT NOT NULL UNIQUE,
    password TEXT NOT NULL
)

Events Table

CREATE TABLE events (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    description TEXT NOT NULL,
    location TEXT NOT NULL,
    dateTime DATETIME NOT NULL,
    user_id INTEGER,
    FOREIGN KEY(user_id) REFERENCES users(id)
)

Registrations Table

CREATE TABLE registrations (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    event_id INTEGER,
    user_id INTEGER,
    FOREIGN KEY(event_id) REFERENCES events(id),
    FOREIGN KEY(user_id) REFERENCES users(id)
)

Security Features

  • Passwords are hashed using bcrypt before storage
  • JWT tokens for stateless authentication
  • Protected routes require valid JWT tokens
  • SQL prepared statements to prevent SQL injection
  • Input validation on all endpoints

About

A RESTful API built with Go and the Gin framework for managing events and user registrations.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages