@@ -55,7 +55,7 @@ Use go get.
5555Then import the form package into your own code.
5656
5757 import "github.com/go-playground/form"
58-
58+
5959Usage
6060-----
6161
@@ -215,8 +215,8 @@ Registering Custom Types
215215Decoder
216216``` go
217217decoder.RegisterCustomTypeFunc (func (vals []string ) (interface {}, error ) {
218- return time.Parse (" 2006-01-02" , vals[0 ])
219- }, time.Time {})
218+ return time.Parse (" 2006-01-02" , vals[0 ])
219+ }, time.Time {})
220220```
221221ADDITIONAL: if a struct type is registered, the function will only be called if a url.Value exists for
222222the struct and not just the struct fields eg. url.Values{"User":"Name%3Djoeybloggs"} will call the
@@ -226,16 +226,16 @@ custom type function with 'User' as the type, however url.Values{"User.Name":"jo
226226Encoder
227227``` go
228228encoder.RegisterCustomTypeFunc (func (x interface {}) ([]string , error ) {
229- return []string {x.(time.Time ).Format (" 2006-01-02" )}, nil
230- }, time.Time {})
229+ return []string {x.(time.Time ).Format (" 2006-01-02" )}, nil
230+ }, time.Time {})
231231```
232232
233233Ignoring Fields
234234--------------
235235you can tell form to ignore fields using ` - ` in the tag
236236``` go
237237type MyStruct struct {
238- Field string ` form:"-"`
238+ Field string ` form:"-"`
239239}
240240```
241241
@@ -244,14 +244,14 @@ Omitempty
244244you can tell form to omit empty fields using ` ,omitempty ` or ` FieldName,omitempty ` in the tag
245245``` go
246246type MyStruct struct {
247- Field string ` form:",omitempty"`
247+ Field string ` form:",omitempty"`
248248 Field2 string ` form:"CustomFieldName,omitempty"`
249249}
250250```
251251
252252Notes
253253------
254- To maximize compatibility with other systems the Encoder attempts
254+ To maximize compatibility with other systems the Encoder attempts
255255to avoid using array indexes in url.Values if at all possible.
256256
257257eg.
0 commit comments