Files
zeekayandHanzo Dev 37b70af0bf bank: one error-response shape + generic bindBody[T] (proper typing)
respond.go holds the two response primitives every handler now shares:
- errJSON(e, status, msg): the single {"error": msg} shape, replacing
  15 hand-spelled map[string]string{"error": ...} returns.
- bindBody[T](e) (T, error): a generic typed body decoder; all nine
  handler body-binds now go through it — one way to read a request
  body, and the result is statically typed instead of a var + pointer
  dance.

No behavior change; build, vet, staticcheck, and the full suite green.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-22 17:26:59 -07:00

21 lines
677 B
Go

package bank
import "github.com/hanzoai/base/core"
// One shape for every handler-level response, so the wire contract is uniform
// and stated in one place rather than re-spelled at each return.
// errJSON writes {"error": msg} with the given status.
func errJSON(e *core.RequestEvent, status int, msg string) error {
return e.JSON(status, map[string]string{"error": msg})
}
// bindBody decodes the request body into T, returning it typed. Replaces the
// `var req T; e.BindBody(&req)` dance at every handler with one call whose
// result is already the right type.
func bindBody[T any](e *core.RequestEvent) (T, error) {
var v T
err := e.BindBody(&v)
return v, err
}