forms
forms copied to clipboard
Intent to Break Backwards Compatibility
I wanted to let the community know that I intend to make major changes to this library in the near future which will not be backwards compatible. I have updated the README with versioning information and recommend that for serious applications you use a dependency vendoring tool, such as godep.
The biggest change is that validation methods will be chainable, as they are in go-humble/form. IMO chainable methods read better and reduce code clutter. We could go from this:
val.Require("age")
val.TypeInt("age")
val.Greater("age", 0)
To this:
form.Validate("age").Required().Int().GreaterThan(0)
As a consequence, instead of calling Message at the end of a validation method, we will need to introduce new methods for adding custom messages. Currently I am thinking to mimic go-humble/form and introduce methods with the f suffix for adding custom messages.
// Requiredf is like Required but allows you to specify a custom error message.
// The arguments format and args work exactly like they do in fmt.Sprintf.
func (val *Validation) Requiredf(format string, args ...interface{}) *Validation
In addition, method names will be more consistent. I want the methods to read nicely without introducing too much verbosity.