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.
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.
- 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
- 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
- Go 1.21+
- Gin Web Framework
- SQLite
- JWT (github.com/golang-jwt/jwt/v5)
- bcrypt (golang.org/x/crypto/bcrypt)
- Clone the repository
- Install dependencies
go mod tidy - Run the application
go run app.go - The API will be available at http://localhost:8080
A new api.db SQLite database will be created automatically.
- Signup:
POST /signup
Create a new user account. - Login:
POST /login
Obtain a JWT token. - Authenticated Requests:
Include the token in theAuthorizationheader (no "Bearer" prefix).
Public:
GET /events– List all eventsGET /events/:id– Get event detailsPOST /signup– Register a new userPOST /login– Authenticate and receive a JWT
Authenticated (JWT required):
POST /events– Create an eventPUT /events/:id– Update an event (creator only)DELETE /events/:id– Delete an event (creator only)POST /events/:id/register– Register for an eventDELETE /events/:id/register– Cancel registration
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.
- The JWT secret is hard-coded for demonstration purposes only.
- The
Authorizationheader expects the raw token (no "Bearer" prefix). - This project is intended for educational use and is not production-ready.