Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Strict = false
Strict enables strict mode wherein the package will panic on an AppendTo function if it finds that a tag string was malformed.
Functions ¶
func AppendTo ¶
func AppendTo(values *Values, i interface{})
AppendTo uses reflection to form encode into the given values collection based off the form tags that it defines.
func AppendToPrefixed ¶
AppendToPrefixed is the same as AppendTo, but it allows a slice of key parts to be specified to prefix the form values.
I was hoping not to have to expose this function, but I ended up needing it for recipients. Recipients is going away, and when it does, we can probably remove it again.
Types ¶
type Appender ¶
type Appender interface { // AppendTo is invoked by the form package on any types found to implement // Appender so that they have a chance to encode themselves. Note that // AppendTo is called in addition to normal encoding, so other form tags on // the struct are still fair game. AppendTo(values *Values, keyParts []string) }
Appender is the interface implemented by types that can append themselves to a collection of form values.
This is usually something that shouldn't be used, but is needed in a few places where authors deviated from norms while implementing various parameters.
type Values ¶
type Values struct {
// contains filtered or unexported fields
}
Values is a collection of values that can be submitted along with a request that specifically allows for duplicate keys and encodes its entries in the same order that they were added.
func (*Values) Get ¶
Get retrieves the list of values for the given key. If no values exist for the key, nil will be returned.
Note that Get is O(n) and may be quite slow for a very large parameter list.
func (*Values) Set ¶
Set sets the first instance of a parameter for the given key to the given value. If no parameters exist with the key, a new one is added.
Note that Set is O(n) and may be quite slow for a very large parameter list.
func (*Values) ToValues ¶
ToValues converts an instance of Values into an instance of url.Values. This can be useful in cases where it's useful to make an unordered comparison of two sets of request values.
Note that url.Values is incapable of representing certain Rack form types in a cohesive way. For example, an array of maps in Rack is encoded with a string like:
arr[][foo]=foo0&arr[][bar]=bar0&arr[][foo]=foo1&arr[][bar]=bar1
Because url.Values is a map, values will be handled in a way that's grouped by their key instead of in the order they were added. Therefore the above may by encoded to something like (maps are unordered so the actual result is somewhat non-deterministic):
arr[][foo]=foo0&arr[][foo]=foo1&arr[][bar]=bar0&arr[][bar]=bar1
And thus result in an incorrect request to Stripe.