How nonlight/test-for-go-pet-shop works
This is a Go Pet Shop HTTP service exposing health checks and product listing, creation, updating, and deletion. Its main workflow is an HTTP request routed to a product handler, validated or decoded, then passed to PostgreSQL storage; the handler returns JSON and errors as HTTP responses. Startup loads configuration, initializes logging and storage, and registers routes. The README emphasizes handler tests and mock variants, but those are excluded from this runtime map. The migration command is shown separately; unsampled migration details are not inferred.
Main entry points: app/main.go App startup · products.go Product handlers · postgres.go Postgres storage · migrator/main.go Migration command
Components 14
HTTP API
- App startup
cmd/app/main.go - Configuration
internal/config/config.go - Logger
internal/lib/logger/logger.go - Chi router
cmd/app/main.go - Health handler
internal/handlers/status.go
Product Domain
- Product handlers
internal/handlers/product/products.go - Product models
internal/models/models.go
Persistence
- Storage errors
internal/storage/storage.go - Postgres storage
internal/storage/postgres/postgres.go - Product queries
internal/storage/postgres/product.go - PostgreSQL
- Migration command
cmd/migrator/main.go - Schema migrations
migrations
Other components
- HTTP client
Connections 14
- HTTP client → Chi router: sends requests
- App startup → Configuration: loads settings
- App startup → Logger: sets up
- App startup → Postgres storage: initializes
- App startup → Chi router: registers routes
- App startup → Product handlers: constructs
- Chi router → Health handler: dispatches health
- Chi router → Product handlers: dispatches products
- Product handlers → Product models: decodes and returns
- Product handlers → Postgres storage: calls product methods
- Postgres storage → Product queries: provides storage
- Product queries → PostgreSQL: queries products
- Migration command → PostgreSQL: applies migrations
- Migration command → Schema migrations: reads migration files