How ieiskyler/user-management works
This is a Gin-based user management REST API. Clients register accounts, log in to receive a JWT, then present that token to access paginated user listings. The main internal layers are routing and authentication middleware, HTTP handlers, business services, and a GORM repository backed by PostgreSQL. Startup wires these components, configures the database connection pool, and migrates the user table. The README documents the endpoint capabilities; connections not demonstrated by the supplied excerpts are omitted.
Main entry points: main.go Application startup · user_handler.go User listing handler · router.go HTTP routing · user_repository.go User repository
Components 17
API runtime
- Application startup
cmd/api/main.go - HTTP routing
internal/server/router.go - API error responses
internal/response/response.go
Identity
- JWT middleware
internal/middleware/auth_middleware.go - Register and login
internal/handler/auth_handler.go - Auth business logic
internal/service/auth_service.go - JWT secret config
internal/config/auth.go
User listing
- User listing handler
internal/handler/user_handler.go - Pagination query
internal/handler/user_query.go - User summaries
internal/handler/user_response.go - User listing service
internal/service/user_service.go
Persistence
- User repository
internal/repository/user_repository.go - User model
internal/models/user.go - Database setup
internal/config/database.go - Pool settings
internal/config/database_pool.go
Other components
- API client
- PostgreSQL
Connections 27
- API client → HTTP routing: sends HTTP requests
README.md - Application startup → Database setup: connects database
cmd/api/main.go - Application startup → User repository: constructs repository
cmd/api/main.go - Application startup → Auth business logic: constructs service
cmd/api/main.go - Application startup → User listing service: constructs service
cmd/api/main.go - Application startup → Register and login: constructs handler
cmd/api/main.go - Application startup → User listing handler: constructs handler
cmd/api/main.go - Application startup → HTTP routing: starts router
cmd/api/main.go - HTTP routing → Register and login: routes auth requests
internal/server/router.go - HTTP routing → JWT middleware: protects user route
internal/server/router.go - HTTP routing → User listing handler: routes user listing
internal/server/router.go - Register and login → Auth business logic: calls auth operations
internal/handler/auth_handler.go - Register and login → API error responses: formats errors
internal/handler/auth_handler.go - Auth business logic → User repository: creates and finds users
internal/service/auth_service.go - Auth business logic → JWT secret config: loads signing secret
internal/service/auth_service.go - JWT middleware → JWT secret config: loads validation secret
internal/middleware/auth_middleware.go - JWT middleware → API error responses: formats errors
internal/middleware/auth_middleware.go - User listing handler → Pagination query: binds and normalizes
internal/handler/user_handler.go - User listing handler → User listing service: requests page
internal/handler/user_handler.go - User listing handler → User summaries: converts user results
internal/handler/user_handler.go - User listing handler → API error responses: formats errors
internal/handler/user_handler.go - User listing service → User repository: fetches page
internal/service/user_service.go - User repository → PostgreSQL: reads and writes users
internal/repository/user_repository.go - User repository → User model: queries user records
internal/repository/user_repository.go - Database setup → Pool settings: loads pool settings
internal/config/database.go - Database setup → PostgreSQL: opens and migrates
internal/config/database.go - Database setup → User model: migrates user table
internal/config/database.go