A robust API server built with Go and Gin for managing events and attendance. This project is primarily a learning resource designed to explore how to integrate Swagger documentation with the Gin framework in Go. It demonstrates a clean architecture approach to building RESTful APIs with Swagger documentation, JWT authentication, and PostgreSQL integration.
- User Authentication: Secure signup and login endpoints using JWT.
- Event Management: Create and retrieve events.
- Protected Routes: Middleware to secure endpoints requiring authentication.
- Swagger Documentation: Interactive API documentation available at
/swagger/index.html. - Database Integration: PostgreSQL support with migration handling.
This project serves as a practical playground for understanding:
- Swagger/OpenAPI: How to annotate Go code to automatically generate interactive API documentation.
- Gin Framework: Routing, middleware, and request handling in Gin.
- Clean Architecture: Structuring a Go application for maintainability and scalability.
- Authentication: Implementing JWT-based security flows.
- Language: Go (1.23+)
- Framework: Gin Web Framework
- Database: PostgreSQL
- Driver: pgx
- Authentication: JWT (JSON Web Tokens)
- Documentation: Swagger (swaggo)
- Migrations: golang-migrate
- Containerization: Docker
.
├── cmd
│ ├── api # Main API application entry point and routes
│ ├── db # Database connection and migrations
│ ├── models # Data models and structures
│ └── utils # Utility functions
├── docs # Swagger documentation files
├── Makefile # Build and run commands
├── Dockerfile # Docker build configuration
├── .dockerignore # Files excluded from Docker context
├── docker-compose.yml # Docker composition for dependencies
└── go.mod # Go module definition
For detailed setup instructions, please refer to setup.md.
- Go 1.23 or higher
- PostgreSQL
- Make (optional, for running Makefile commands)
-
Clone the repository
git clone https://github.com/Walon-Foundation/go-gin-doc.git cd go-gin-doc -
Setup Environment Variables Create a
.envfile in the root directory:PORT=5000 JWT_SECRET=your_super_secret_key DB_URL=postgres://user:password@localhost:5432/dbname?sslmode=disable
-
Run the Application
make dev
Or manually:
go run ./cmd/api
-
Access the API
- Server running at:
http://localhost:5000 - Swagger Docs:
http://localhost:5000/swagger/index.html
- Server running at:
-
Run with Docker (Optional)
# Build the image docker build -t go-gin-doc . # Run the container (ensure DB_URL points to a reachable database) docker run -p 8080:8080 --env-file .env -e PORT=8080 go-gin-doc
This project is licensed under the MIT License - see the LICENSE file for details.
For security considerations and reporting vulnerabilities, please see security.md.