Documentation
¶
Overview ¶
Package binders parses HTTP request bodies and coerces values into typed request structs.
Responsibility boundary ¶
The binder handles:
- Parsing JSON and multipart/form-data request bodies
- Coercing raw values (string, float64, bool) to Go struct field types
Typical handler flow ¶
// Step 1: binder parses body
request := ctx.MustGet("request").(*CreateCustomerRequest)
// Step 2: validator runs stateful rules (only when needed)
v := validator.New(ctx, db)
if err := v.Validate(request); err != nil {
_ = ctx.Error(err)
return
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindRaw ¶
BindRaw is the testable core of BindRequest. Call this in unit tests to avoid needing an HTTP server or gin context.
raw := map[string]any{"vrsta": float64(1), "prezime": "Doe"}
var req UpdateCustomerRequest
err := binders.BindRaw(&req, raw, false)
func BindRequest ¶
BindRequest parses and validates the request body into v. Supports Content-Type: application/json and multipart/form-data.
Returns nil on success. Returns ErrValidation with field-level messages on validation failure. Returns ErrBadRequest if the body is unreadable or malformed JSON.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.