I ended up using this approach:
http://www.alexedwards.net/blog/form-validation-and-processi...
This is straightforward but also manual and low-level.
In comparison is Python's formencode library which is declarative and high-level:
class Registration(formencode.Schema):
first_name = validators.ByteString(not_empty=True)
last_name = validators.ByteString(not_empty=True)
email = validators.Email(resolve_domain=True)
username = formencode.All(validators.PlainText(),UniqueUsername())
password = SecurePassword()
password_confirm = validators.ByteString()
chained_validators = [validators.FieldsMatch('password', 'password_confirm')]
I thought about how you could design a library like this in Go, but couldn't think of a way that did not end up using reflection or plain maps, which defeats the purpose of using static typing.Is this lack of validation libraries due to the lack of people writing web apps with the language or is it a problem of expressiveness with the language itself?
I ran into this issue several times when trying to write a web app in Go. A lot of the basic infrastructure is there, but the niceties are missing. The template language, for example, is great but lacks something as basic as inheritance without kludges. There are other templating languages, but they don't feel quite there. Got the same feel from the ORMs. Hats off to those who are doing work in it in spite of this, but it seems there's a way to go before the language is really usable for web apps.