How Request Decoders work
masterThe Request Decoder maps HTTP request data into Go structs using field tags. This allows you to define your input port (the data your business logic needs) and its validation constraints in a single place.
Supported parameter locations via tags:
path: URI parameters (e.g.,/users/{name})query: URL query parameters (e.g.,?locale=en-US)formData: Request body withapplication/x-www-form-urlencodedormultipart/form-dataform: Acts as eitherformDataorqueryjson: Request body withapplication/jsoncookie: Request cookiesheader: HTTP request headerscontentType: The content type of the raw request body
To disallow unknown parameters, use an unnamed field with tags like query:"_" or cookie:"_" and set additionalProperties:"false".
type helloInput struct {
Locale string `query:"locale" default:"en-US" pattern:"^[a-z]{2}-[A-Z]{2}$" enum:"ru-RU,en-US"`
Name string `path:"name" minLength:"3"`
// Disallow unknown query and cookie parameters
_ struct{} `query:"_" cookie:"_" additionalProperties:"false"`
}