How faustaakbar/golang-restapi works
This is a layered Go REST API for listing and creating users. An HTTP client reaches the Gin routes, which dispatch to handlers; handlers call the user service, which coordinates Redis caching and repository operations backed by MySQL. Startup loads configuration, connects to both stores, migrates the user model, and registers routes. The README also documents five-minute list caching and cache invalidation after creation. Relationships are based on the shown source and README; Docker Compose infrastructure is omitted as development setup.
Main entry points: main.go Application Entry · user_service.go User Service · user.go User Model · mysql.go MySQL Connection
Components 12
Application Startup
- Application Entry
cmd/main.go - Environment Config
internal/config/config.go - MySQL Connection
internal/database/mysql.go - Redis Connection
internal/database/redis.go
User API
- API Routes
internal/routes/routes.go - User Handler
internal/handler/user_handler.go - User Service
internal/service/user_service.go
Data Access
- User Model
internal/models/user.go - User Repository
internal/repository/user_repository.go
Other components
- HTTP Client
- MySQL Store
- Redis Cache
Connections 18
- HTTP Client → API Routes: sends requests
README.md - Application Entry → Environment Config: loads config
cmd/main.go - Application Entry → MySQL Connection: connects
cmd/main.go - Application Entry → Redis Connection: connects
cmd/main.go - Application Entry → User Model: migrates schema
cmd/main.go - Application Entry → API Routes: registers routes
cmd/main.go - MySQL Connection → Environment Config: reads settings
internal/database/mysql.go - Redis Connection → Environment Config: reads settings
internal/database/redis.go - MySQL Connection → MySQL Store: opens connection
internal/database/mysql.go - Redis Connection → Redis Cache: opens connection
internal/database/redis.go - API Routes → User Handler: dispatches requests
internal/routes/routes.go - User Handler → User Service: calls service
internal/handler/user_handler.go - User Service → User Repository: queries users
internal/service/user_service.go - User Service → Redis Cache: reads and invalidates cache
internal/service/user_service.go - User Repository → MySQL Store: reads and writes
internal/repository/user_repository.go - User Repository → User Model: uses user records
internal/repository/user_repository.go - User Service → User Model: processes users
internal/service/user_service.go - User Handler → User Model: binds request data
internal/handler/user_handler.go