Documentation ¶
Overview ¶
Package reqconv implements auto parsing a HTTP request as golang struct according to its content type. The supported content type are:
- application/json
- application/xml
- multipart/form-data
- application/x-www-form-urlencoded
For a request without body, e.g., GET, DELETE, HEAD, TRACE, it will parse the URL query into given pointer.
It returns a error when other types incoming.
As of Golang struct, the supported types are:
- int
- bool
- string
- float64
- *multipart.FileHeader
- slice of above
For example, a file upload request:
var params struct { Int int `json:"int"` Bool bool `json:"bool"` File *multipart.FileHeader `json:"file"` Array []string `json:"array"` } params.Int = 233 // default value if any. err := reqconv.Unmarshal(req, ¶ms)
By default, the form data key uses `json`, same as json for consistency. You can change it by:
form.FieldTag = "form"
If no tag specified, it will use cammel case of the field name since most languages fields start with lower case.
As of xml, however, you must use the `xml` tag.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.