Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BodyFromMap ¶
BodyFromMap creates a multipart/formdata encoded body by applying a transform function to generate form parts for each item in a map. Configuration functions can be used to set the boundary string and the transformation function.
Returns ¶
string // the content type for the body []byte // the body error // an error (if non-nil, content type and body should be ignored)
Configuration Functions ¶
// to set the boundary string for the body Boundary(string) // to set the transformation function for the body TransformMap(func(K, V) (string, string, []byte, error))
If no boundary is configured, "boundary" is used.
If no transformation function is configured a default transformation is applied (see: TransformMap for details).
If the transformation function returns an error for any item then this will be returned as the error from BodyFromMap; the returned body and content type will be empty and should be ignored.
Example ¶
Demonstrates using the `BodyFromMap` function to create a multipart/formdata encoded body from a map, with a custom boundary string and transformation:
ct, body, err := BodyFromMap( map[string]string{"part-id": "content data"}, Boundary("ABCDEF"), MapTransform(func(k, v string) (string, string, []byte, error) { return "field-" + k, "filename-" + k, []byte(v), nil }), )
func Boundary ¶
Boundary is a configuration function that sets the boundary string for the multipart body.
If no boundary is set then "boundary" is used.
func TransformMap ¶
TransformMap sets the transformation function for the BodyFromMap function.
If no transformation function is set then the default transformation is applied. This will create a part for each key:value pair in the map, with:
- the key as the fieldname
- an empty string as the filename
- an octet-stream ([]byte) containing the string representation of the value as the content
If the supplied transformation function returns an error for any item then this will be returned as the error from BodyFromMap; the returned body and content type will be empty and should be ignored.