A simple RESTful API for event management built with Go, Gin, and SQLite. This project demonstrates user authentication (JWT), event CRUD operations, and event registration/cancellation.
- User signup and login with password hashing (bcrypt)
- JWT-based authentication middleware
- CRUD operations for events
- Event registration and cancellation
- SQLite database with auto-migration
- Organized code structure (models, routes, middlewares, utils)
- Go 1.18+
- SQLite3
-
Clone the repository:
git clone https://github.com/yourusername/go-rest-api.git cd go-rest-api -
Install dependencies:
go mod tidy
-
Run the application:
go run main.go
The API will be available at http://localhost:8080.
POST /signup— Register a new userPOST /login— Login and receive JWTGET /events— List all eventsGET /events/:id— Get event by ID
POST /events— Create eventPUT /events/:id— Update event (owner only)DELETE /events/:id— Delete event (owner only)POST /events/:id/register— Register for eventDELETE /events/:id/register— Cancel registration
See the api-test/ directory for sample HTTP requests using REST Client.
.
├── api-test/ # Sample HTTP requests
├── db/ # Database initialization
├── middlewares/ # JWT authentication middleware
├── models/ # Database models
├── routes/ # API route handlers
├── utils/ # Utility functions (hashing, JWT)
├── main.go # Entry point
└── go.mod, go.sum # Go modules
- Uses SQLite (
api.db). - Tables:
users,events,registrations. - Tables are auto-created on startup.
- Passwords are hashed with bcrypt.
- JWT tokens are used for authentication and must be sent in the
Authorizationheader.
Note: This project is for educational/demo purposes. For production, use environment variables for secrets, add input validation, and follow security best practices.