A small HTTP handler in Go needs to be reviewed.
Context: the service accepts invoice confirmation POST /invoices/finalize with a JSON body like { "invoice_id": "inv-1", "amount": 1200 } and records an event in a transaction log. After a successful commit, the handler must return 204 No Content.
Functional contract:
POST only, otherwise 405;400;408 Request Timeout;500.Given:
go test ./...;Ledger may be called concurrently from multiple goroutines, its methods are already protected by sync.Mutex; no additional background goroutines are required in the solution;Review task:
Verification hint: it is enough to reproduce scenarios through net/http/httptest and go test ./..., including a canceled context before entering the write path and branches with early handler exits.
Go 1.24, standard library only. Verification: go test ./.... A normal net/http server is assumed, without middleware that automatically closes or drains the request body. Ledger.Commit and Ledger.Append may be called concurrently, and internal synchronization is already present in the code.
Use line comments to explain the problem, its impact, the fix and how to test it.