A simple REST API for managing events and attendees, built with Go, Gin, SQLite, and Swagger documentation.
- This repository is a study project inspired by the YouTube series from Coding with Patrik.
- Original video: https://www.youtube.com/watch?v=ERZadn9artM&t=1s
- Channel: https://www.youtube.com/@codingwithpatrik
- The goal is to practice building a small, full-stack-friendly API using idiomatic Go, Gin for HTTP routing, SQLite for persistence, database migrations, and autogenerated Swagger docs.
- 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
- 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
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
- Go installed and
~/go/binon yourPATH - 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- Install dependencies:
go mod tidy- Generate Swagger docs:
swag init --dir cmd/api --parseDependency --parseInternal --parseDepth 1- Create and apply database migrations (SQLite
data.dbin 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- With Air (recommended):
air- Without Air:
go run cmd/api/main.goServer starts on http://localhost:8080.
- 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"
)Minimal configuration is embedded; extend cmd/internal/env/env.go for environment variables (e.g., JWT secret, DB path) as needed.
Base path: /api/v1
GET /api/v1/events— list eventsGET /api/v1/events/:id— get event by idPOST /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 eventGET /api/v1/attendees/:id/events— list events by attendeePOST /api/v1/auth/register— registerPOST /api/v1/auth/login— login
- For SQLite,
golang-migrateuses direct SQL files incmd/migrate/migrations. - The
Deletemethod returns404if the resource doesn’t exist (checked viaRowsAffected).
- If Swagger returns 404, restart Air or rerun
swag init. - Prefer relative URL
"/swagger/doc.json"inroutes.goto avoid hardcoding host.
This project is for learning purposes and does not include an explicit license. Add one if you plan to distribute it.