Skip to content

Commit 5b5b101

Browse files
author
joeybloggs
committed
Add to RegisterCustomTypeFunc documentation
- Added additional notes to RegisterCustomTypeFunc to indicate that if a struct type is registered a url.Value must exist explicitly for the struct and not just the fields. eg. url.Values{"User":"Name%3Djoeybloggs"} will call the custom type function with `User` as the type, however url.Values{"User.Name":"joeybloggs"} will not. Fixes #14
1 parent d18f249 commit 5b5b101

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package form
22
============
33
<img align="right" src="https://raw.githubusercontent.com/go-playground/form/master/logo.jpg">
4-
![Project status](https://img.shields.io/badge/version-2.2.0-green.svg)
4+
![Project status](https://img.shields.io/badge/version-2.2.1-green.svg)
55
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/form/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/form)
66
[![Coverage Status](https://coveralls.io/repos/github/go-playground/form/badge.svg?branch=master)](https://coveralls.io/github/go-playground/form?branch=master)
77
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/form)](https://goreportcard.com/report/github.com/go-playground/form)
@@ -217,6 +217,10 @@ decoder.RegisterCustomTypeFunc(func(vals []string) (interface{}, error) {
217217
return time.Parse("2006-01-02", vals[0])
218218
}, time.Time{})
219219
```
220+
ADDITIONAL: if a struct type is registered, the function will only be called if a url.Value exists for
221+
the struct and not just the struct fields eg. url.Values{"User":"Name%3Djoeybloggs"} will call the
222+
custom type function with 'User' as the type, however url.Values{"User.Name":"joeybloggs"} will not.
223+
220224

221225
Encoder
222226
```go

doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ Decoder
210210
return time.Parse("2006-01-02", vals[0])
211211
}, time.Time{})
212212
213+
ADDITIONAL: if a struct type is registered, the function will only be called
214+
if a url.Value exists for the struct and not just the struct fields
215+
eg. url.Values{"User":"Name%3Djoeybloggs"} will call the custom type function
216+
with 'User' as the type, however url.Values{"User.Name":"joeybloggs"} will not.
217+
213218
Encoder
214219
215220
encoder.RegisterCustomTypeFunc(func(x interface{}) ([]string, error) {

form_decoder.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ func (d *Decoder) SetMaxArraySize(size uint) {
112112
d.maxArraySize = int(size)
113113
}
114114

115-
// RegisterCustomTypeFunc registers a CustomTypeFunc against a number of types
116-
// NOTE: this method is not thread-safe it is intended that these all be registered prior to any parsing
115+
// RegisterCustomTypeFunc registers a CustomTypeFunc against a number of types.
116+
// NOTE: This method is not thread-safe it is intended that these all be registered prior to any parsing
117+
//
118+
// ADDITIONAL: if a struct type is registered, the function will only be called if a url.Value exists for
119+
// the struct and not just the struct fields eg. url.Values{"User":"Name%3Djoeybloggs"} will call the
120+
// custom type function with `User` as the type, however url.Values{"User.Name":"joeybloggs"} will not.
117121
func (d *Decoder) RegisterCustomTypeFunc(fn DecodeCustomTypeFunc, types ...interface{}) {
118122

119123
if d.customTypeFuncs == nil {

0 commit comments

Comments
 (0)