A simple and secure REST API built using Go (Golang), the Gin framework, and JWT authentication for managing events and users.
- User registration and login
- JWT-based authentication with token expiry
- Event creation, listing, and management
- Middleware for token verification and route protection
- Modular code structure for scalability
- Go (Golang)
- Gin HTTP Web Framework
- JWT for authentication
- MySQL (or compatible) database
.
├── main.go # Application entry point
├── api-test # Postman/test collections
├── db # Database connection and setup
├── middlewares # Authentication and other middlewares
├── models # Database models
├── routes # API route definitions
├── utils # Helper utilities (JWT, password hashing)
└── README.md
- Clone the repository:
git clone https://github.com/Rohitth10e/event-management-api.git
cd event-management-api- Install dependencies:
go mod tidy-
Configure environment variables:
- Set your database connection string in
db/connection.go. - Update
JWT_SECRET_KEYin.envorutils/token.go.
- Set your database connection string in
-
Run the server:
go run main.go- API available at:
http://localhost:8081
- Signup: POST
/signupwith email and password. - Login: POST
/loginto receive JWT token. - Use Token: Include
Authorization: Bearer <token>for protected endpoints. - Token expires in 2 hours (configurable in
utils/token.go).
POST /signup
{
"EMAIL": "user@example.com",
"PASSWORD": "password123"
}POST /login
{
"EMAIL": "user@example.com",
"PASSWORD": "password123"
}Response: { "token": "<jwt_token>" }
POST /events
Headers: Authorization: Bearer <jwt_token>
{
"NAME": "My Event",
"DESCRIPTION": "An awesome event",
"LOCATION": "Bangalore"
}- Always send the token in the
Authorizationheader for protected routes. - Token expiry: 2 hours.
- Date fields should follow ISO 8601 (
YYYY-MM-DDorYYYY-MM-DDTHH:mm:ssZ). - For local testing, configure CORS in the backend if needed.
- Example workflow: User signs up → logs in → stores JWT in secure storage (not localStorage) → includes it in all API requests.
We welcome contributions! To contribute:
- Fork the repository.
- Create a feature branch:
git checkout -b feature-name. - Commit changes with a descriptive message:
git commit -m "Description of changes". - Push your branch:
git push origin feature-name. - Open a Pull Request explaining your changes.
- Write clear, concise commit messages.
- Follow Go best practices and code formatting (
go fmt). - Update documentation where necessary.
- Add or update tests for any changes.
-
Report bugs or request features via the GitHub Issues tab.
-
Include:
- Steps to reproduce
- Expected vs actual behavior
- Environment details (OS, Go version, etc.)
MIT License