How bjhabibie59/golang-rest-api works
This is a small Go HTTP API for user registration, login, and authenticated user listing, backed by MySQL. The main flow is route dispatch to handlers, service logic, and repository operations; authentication adds JWT issuance and request validation. The entry point wires these layers and configures the database. The README also advertises CRUD, though the shown routes implement only user listing, registration, and login. Relationships are limited to calls and wiring visible in the excerpts; the MySQL connection is documented by the database configuration code.
Main entry points: main.go Server Wiring · user_handler.go User Handler · auth_service.go Auth Service · user_repository.go User Repository
Components 12
HTTP API
- Server Wiring
cmd/main.go - Auth Handler
internal/handler/auth_handler.go - User Handler
internal/handler/user_handler.go - JWT Middleware
internal/middleware/auth_middleware.go
User Domain
- Auth Service
internal/service/auth_service.go - User Service
internal/service/user_service.go - User Model
internal/model/user.go
Persistence
- User Repository
internal/repository/user_repository.go - DB Connection
internal/config/database.go
Runtime Support
- JSON Response
pkg/response/json.go
Other components
- API Client
- MySQL
Connections 20
- API Client → Server Wiring: sends requests
cmd/main.go - Server Wiring → DB Connection: opens database
cmd/main.go - DB Connection → MySQL: connects and migrates
internal/config/database.go - DB Connection → User Model: migrates and seeds
internal/config/database.go - Server Wiring → User Repository: creates with DB
cmd/main.go - Server Wiring → Auth Service: wires repository
cmd/main.go - Server Wiring → User Service: wires repository
cmd/main.go - Server Wiring → Auth Handler: registers routes
cmd/main.go - Server Wiring → User Handler: registers users route
cmd/main.go - Server Wiring → JWT Middleware: protects users route
cmd/main.go - JWT Middleware → User Handler: dispatches authorized
- Auth Handler → Auth Service: registers or logs in
internal/handler/auth_handler.go - Auth Handler → JSON Response: formats replies
internal/handler/auth_handler.go - User Handler → User Service: fetches users
internal/handler/user_handler.go - User Handler → JSON Response: formats replies
internal/handler/user_handler.go - JWT Middleware → JSON Response: formats auth errors
internal/middleware/auth_middleware.go - Auth Service → User Repository: creates or finds user
internal/service/auth_service.go - Auth Service → User Model: builds user
internal/service/auth_service.go - User Service → User Repository: lists users
internal/service/user_service.go - User Repository → User Model: queries user records
internal/repository/user_repository.go