martini-contrib / binding

Martini handler for mapping and validating a raw request into a structure.
MIT License
140 stars 47 forks source link

Binding to params #37

Closed richardcrichardc closed 9 years ago

richardcrichardc commented 9 years ago

Was thinking it would be cool if binding could bind to martini params. If this is something you guys think would be cool I will try and find some time to hack it up.

mholt commented 9 years ago

Aren't params bound to a variable for us already? I'm probably misunderstanding, so feel free to show an example. :+1:

richardcrichardc commented 9 years ago

I was thinking if you had a route like:

/things/:section/:id

You could define a type:

type Thing struct {
    Section   string `param:"section" binding:"required"`
    Id   int `param:"id" binding:"required"`
}

Then leverage Bind's data validation. Maybe this is silly and I am missing a more obvious way to validate params.

mholt commented 9 years ago

Ah, you're thinking of using it for validation. I had never thought about that, but I guess I like the idea. I'd be interested in seeing a pull request whenever you get around to it!