How lkorsman/golang_learning works
Go Store API serves product CRUD and user registration/login, with JWT protection for product writes. Its API entry point wires handlers, middleware, persistence, caching, and chat; product requests validate inputs, use the store, and optionally cache results. A separate WebSocket workflow connects CLI users to a shared chat hub. The README also documents migrations and Prometheus observability. Product, auth, middleware, cache, and chat links are supported by excerpts; unsampled migration and configuration details are represented only where documented or wired by the API entry point.
Main entry points: main.go HTTP API · product/handler.go Product endpoints · auth/handler.go Auth endpoints · middleware.go HTTP middleware
Components 21
API runtime
- HTTP API
cmd/api/main.go - HTTP middleware
internal/http/middleware.go - Prometheus metrics
internal/metrics/metrics.go - Configuration
internal/config/config.go - Metrics endpoint
Products and storage
- Product endpoints
internal/product/handler.go - Product validation
internal/product/validation.go - MySQL product store
internal/product/mysql_store.go - Database migrations
migrations - Redis cache
internal/cache/redis.go - MySQL database
- Redis
Authentication
- Auth endpoints
internal/auth/handler.go - JWT manager
internal/auth/jwt.go - User store
internal/auth/store.go - User model
internal/auth/user.go
Real-time chat
- Chat HTTP handler
internal/chat/handler.go - Chat connection
internal/chat/client.go - Chat hub
internal/chat/hub.go - Chat CLI
cmd/chat-client/main.go
Other components
- API user
Connections 26
- API user → HTTP API: sends requests
README.md - HTTP API → Configuration: loads settings
cmd/api/main.go - HTTP API → HTTP middleware: installs middleware
cmd/api/main.go - HTTP API → Auth endpoints: routes auth
cmd/api/main.go - HTTP API → Product endpoints: routes products
cmd/api/main.go - HTTP API → Chat HTTP handler: routes chat
cmd/api/main.go - HTTP API → Metrics endpoint: serves metrics
cmd/api/main.go - HTTP middleware → Prometheus metrics: records requests
internal/http/middleware.go - HTTP middleware → JWT manager: verifies tokens
internal/http/middleware.go - HTTP middleware → User store: loads user
internal/http/middleware.go - Auth endpoints → User store: creates or reads
internal/auth/handler.go - Auth endpoints → JWT manager: generates tokens
internal/auth/handler.go - Auth endpoints → Prometheus metrics: records auth
internal/auth/handler.go - Auth endpoints → User model: returns user
internal/auth/handler.go - Product endpoints → Product validation: validates input
internal/product/handler.go - Product endpoints → MySQL product store: uses product store
- Product endpoints → Redis cache: reads and invalidates
internal/product/handler.go - Product endpoints → Prometheus metrics: records product activity
internal/product/handler.go - MySQL product store → MySQL database: queries
internal/product/mysql_store.go - MySQL product store → Database migrations: runs migrations
internal/product/mysql_store.go - Redis cache → Redis: reads and writes
internal/cache/redis.go - Chat HTTP handler → Chat hub: registers clients
internal/chat/handler.go - Chat HTTP handler → Chat connection: starts pumps
internal/chat/handler.go - Chat connection → Chat hub: broadcasts messages
internal/chat/client.go - Chat CLI → Chat HTTP handler: connects by WebSocket
README.md - Metrics endpoint → Prometheus metrics: exposes metrics