Skip to content

edgar-lins/event-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Event Manager API

A simple REST API for managing events and attendees, built with Go, Gin, SQLite, and Swagger documentation.

Description

Features

  • Create, update, delete, and list events
  • Manage attendees per event
  • Basic auth: register and login with JWT middleware
  • Database migrations via golang-migrate
  • Auto-reload development server with Air
  • Swagger docs generated with swag

Tech Stack

  • Go 1.25
  • Gin (github.com/gin-gonic/gin)
  • SQLite (github.com/mattn/go-sqlite3)
  • Migrations: github.com/golang-migrate/migrate
  • Swagger: github.com/swaggo/swag, github.com/swaggo/gin-swagger, github.com/swaggo/files

Project Structure

cmd/
  api/
    auth.go
    context.go
    events.go
    main.go
    middleware.go
    routes.go
    server.go
  internal/
    database/
      attendees.go
      events.go
      models.go
      users.go
    env/
      env.go
  migrate/
    main.go
    migrations/
      000001_create_users_table.*.sql
      000002_create_events_table.*.sql
      000003_create_attendees_table.*.sql
docs/
  docs.go
  swagger.json
  swagger.yaml

Prerequisites

  • Go installed and ~/go/bin on your PATH
  • Install Air (optional for live reload): go install github.com/air-verse/air@latest
  • Install Swag CLI: go install github.com/swaggo/swag/cmd/swag@latest

Ensure PATH includes Go bin:

echo 'export PATH=$PATH:$HOME/go/bin' >> ~/.zshrc && source ~/.zshrc

Setup

  1. Install dependencies:
go mod tidy
  1. Generate Swagger docs:
swag init --dir cmd/api --parseDependency --parseInternal --parseDepth 1
  1. Create and apply database migrations (SQLite data.db in repo root):
# Example: create new migration files
migrate create -ext sql -dir ./cmd/migrate/migrations -seq create_example

# Apply migrations
go run cmd/migrate/main.go up

# Rollback (if needed)
go run cmd/migrate/main.go down

Running

  • With Air (recommended):
air
  • Without Air:
go run cmd/api/main.go

Server starts on http://localhost:8080.

Swagger UI

  • UI: http://localhost:8080/swagger
  • JSON: http://localhost:8080/swagger/doc.json

If the UI doesn’t load, ensure docs package is imported in routes.go:

import (
    _ "event-manager/docs"
)

Environment

Minimal configuration is embedded; extend cmd/internal/env/env.go for environment variables (e.g., JWT secret, DB path) as needed.

API Endpoints

Base path: /api/v1

  • GET /api/v1/events — list events
  • GET /api/v1/events/:id — get event by id
  • POST /api/v1/events — create event (auth)
  • PUT /api/v1/events/:id — update event (auth)
  • DELETE /api/v1/events/:id — delete event (auth)
  • GET /api/v1/events/:id/attendees — list attendees for event
  • GET /api/v1/attendees/:id/events — list events by attendee
  • POST /api/v1/auth/register — register
  • POST /api/v1/auth/login — login

Migration Notes

  • For SQLite, golang-migrate uses direct SQL files in cmd/migrate/migrations.
  • The Delete method returns 404 if the resource doesn’t exist (checked via RowsAffected).

Development Tips

  • If Swagger returns 404, restart Air or rerun swag init.
  • Prefer relative URL "/swagger/doc.json" in routes.go to avoid hardcoding host.

License

This project is for learning purposes and does not include an explicit license. Add one if you plan to distribute it.

About

A simple REST API for managing events and attendees, built with Go, Gin, SQLite, and Swagger documentation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages