Comments (4)
You can either implement FieldMapper and define your own Binder func, or you can implement the Binder interface directly (as long as you defined the type in the same package):
func (t *MyTypes) Bind(fieldName string, strVals []string, errs binding.Errors) binding.Errors {
for _, v := range strVals {
*t = append(t, v)
}
return errs
}
Or something like that. Since you're deserializing into a slice of structs, you would probably initialize a struct for each iteration of the for loop. Is that what you're asking for?
from binding.
(Strange - why does GitHub say I both added and removed the 'question' label? It still shows up for me...)
Not directly, but you can type alias the array/slice like:
type MyTypes []MyType
Where MyTypes
implements FieldMapper.
By the way, if you have thoughts about improving this package (related to this question or other things), feel free to comment here or in #28.
from binding.
But doesn't FieldMap only allow you to define logic for deserializing an object? What would the FieldMapper definition look like for an array?
from binding.
Yep. Thanks @mholt!
from binding.
Related Issues (20)
- Expose *Binder interface for more byte oriented payloads HOT 2
- Feature request: Content-Type constraints HOT 1
- Re-thinking the binding package HOT 7
- template errors HOT 1
- 400 instead of 422 HOT 8
- Ability to control the HTTP error codes HOT 1
- autobindings to automatically create FieldMap functions for your structs HOT 1
- binding.Field.Required = true, ignored for struct fields. HOT 4
- JSON file as opposed to HTTPRequest? HOT 1
- Why not use govalidator internally? HOT 1
- Customise error message HOT 7
- Required error changed HOT 1
- Uploading file and json HOT 3
- Should FieldSpec.Binder have higher precedence than Binder.Bind?
- Errors object passed to Validate does not contain errors accumulated during Binding
- Automatic decoding of string HOT 1
- Best practice for operating on slices of data and keeping context HOT 4
- Binding Custom Types by Specifying Binder Func Does Not Work HOT 1
- [bug] error http: multipart handled by ParseMultipartForm if parse form before call binding.Bind HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from binding.