Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Marshal ¶
Marshal serializes the provided struct into a map containing form values. `src` is the struct to be serialized, and the resulting map is returned.
Example:
var data SampleForm formData, err := form.Marshal(data) if err != nil { ... }
func Unmarshal ¶
Unmarshal iterates over the fields in `dest`, populating them with the appropriate fields from the provided source map. `src` is a map containing form values, and `dest` is a pointer to the struct that will be populated.
Example:
var r *http.Request err := r.ParseForm() if err != nil { ... } var submission SampleForm err := form.Unmarshal(r.Form, &submission) if err != nil { ... }
Form data is flat, with key/value pairings: `field = val`, where `field` is matched to a struct tag. Forms allow the same key to be reused: `field = val1, field = val2`. Multiple values can be handled by using a slice in the struct. Dynamic values are encoded in the keys with a `field[key] = val` syntax. Use `map[string]<type>` as the struct type to unmarshal these dynamic pairs.
If multiple form values are provided for a field, parse all values. If the value is not a slice, the first form value is set to the struct's field.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder is responsible for decoding form data from the source map to the provided destination struct.
func NewDecoder ¶
NewDecoder creates a new Decoder instance with the given source form data.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is responsible for encoding struct data into form values.
func NewEncoder ¶
NewEncoder creates a new Encoder instance with the given destination map.
type ErrorDecode ¶
type ErrorDecode struct {
// contains filtered or unexported fields
}
ErrorDecode represents an error that occurs during the decoding process.
func (ErrorDecode) Error ¶
func (e ErrorDecode) Error() string
Error returns the error message for ErrorDecode.
type ErrorEncode ¶
type ErrorEncode struct {
// contains filtered or unexported fields
}
ErrorEncode represents an error that occurs during the encoding process.
func (ErrorEncode) Error ¶
func (e ErrorEncode) Error() string
Error returns the error message for ErrorEncode.