How bintangstilllerning/belajar-golang-restful-api works
This is a Go HTTP REST API for category CRUD. A client request passes through API-key middleware and the routes configured in main.go to category handlers; handlers delegate validation, transaction handling, and category operations to the service, which calls the repository for SQL access. Responses are serialized as JSON, with panics handled by the registered error handler. The source excerpts show category endpoints and MySQL setup; the README is empty, so other product capabilities are not documented.
Main entry points: main.go Server and routes · category_controller_impl.go Category handlers · category_service_impl.go Category service · category_repository_impl.go Category repository
Components 14
HTTP API
- Server and routes
main.go - API-key middleware
middleware/auth_middleware.go - Category handlers
controller/category_controller_impl.go - Error responses
exception/error_handler.go
Category Operations
- Category service
service/category_service_impl.go - Category entity
model/domain/category.go - API models
model/web/category_create_request.go - Response models
model/web/web_response.go - JSON and mapping helpers
helper/json.go
Persistence
- Category repository
repository/category_repository_impl.go - Database setup
app/database.go - SQL connection pool
Other components
- API client
- MySQL
Connections 18
- API client → API-key middleware: sends HTTP
- API-key middleware → Server and routes: forwards request
- Server and routes → Category handlers: routes request
- Server and routes → Error responses: dispatches panic
- Category handlers → Category service: calls operations
- Category handlers → JSON and mapping helpers: reads and writes JSON
- Category service → Category repository: calls queries
- Category service → SQL connection pool: begins transactions
- Category service → JSON and mapping helpers: maps responses
- Category repository → SQL connection pool: executes SQL
- Category repository → Category entity: loads and saves
- Database setup → SQL connection pool: opens connection
- SQL connection pool → MySQL: connects to
- Server and routes → Database setup: initializes database
- Server and routes → Category service: wires dependencies
- Server and routes → Category handlers: wires dependencies
- Category handlers → API models: decodes requests
- Category handlers → Response models: encodes responses