Error handling for Go HTTP servers — structured error responses, error wrapping,
88
81%
Does it follow best practices?
Impact
99%
1.80xAverage score across 5 eval scenarios
Passed
No known issues
A small warehouse company needs a REST API to track its inventory. Build it using Go with net/http (standard library).
Resources:
{ id, sku, name, quantity, location }Endpoints:
GET /api/products -- list all productsGET /api/products/{id} -- get a single product by IDPOST /api/products -- create a product (sku required and must be unique, name required, quantity >= 0)PUT /api/products/{id} -- update a productDELETE /api/products/{id} -- delete a productPOST /api/products/{id}/adjust -- adjust stock quantity (body: { "delta": 5 } or { "delta": -3 }). Quantity must not go below zero.Use in-memory storage (no real database needed). Seed with 3 sample products.
Produce:
main.go -- server entry point and route registrationerrors.go -- error typeshandlers.go -- route handlersmodels.go -- data types and in-memory storego.mod -- module definitionYou may create additional files as needed for a well-structured codebase.