The application uses Gorilla Mux for routing with global middleware:
router := mux.NewRouter()
router.Use(middleware.ErrorHandler)
router.Use(middleware.RateLimiter)-
Swagger Documentation
GET /swagger/- API documentation interface
-
Health Check
GET /api/v1/health- Server health status
-
Authentication
POST /api/v1/auth/register- User registrationPOST /api/v1/auth/login- User login
All protected routes require JWT authentication and specific role-based access:
GET /api/v1/users/profile- User profile (Requiresadminorpremiumrole)GET /api/v1/protected- Generic protected route
// JWT verification middleware
token := r.Header.Get("Authorization")
// Format: Bearer <token>- Implemented through middleware
- Supports multiple roles (e.g., "admin", "premium")
- PostgreSQL database required
- Database name:
crmdb
- Install dependencies:
go mod tidy- Install Swagger CLI:
go install github.com/swaggo/swag/cmd/swag@latest- Generate Swagger docs:
swag init -g cmd/main.go- Run the server:
go run cmd/main.goServer runs at http://localhost:8080
Using air for development:
go install github.com/cosmtrek/air@latest
air init
air- Swagger UI available at:
http://localhost:8080/swagger/index.html - Authentication format:
Authorization: Bearer <your_token_here>
- Environment variables are properly secured (
.envin.gitignore) - JWT tokens required for protected routes
- Role-based access control implemented
- Rate limiting enabled