bazooka-ci / bazooka

Continuous Integration and Continuous Deployment Server
http://docs.bazooka-ci.io/
MIT License
60 stars 5 forks source link

Improve validation: use tagName 'validate' to add constraints on a field #225

Closed haklop closed 9 years ago

haklop commented 9 years ago

Use gopkg.in/bluesuncorp/validator.v5 to validate submitted JSON.

Simply add the validate tag on a field to set constraints:

type Project struct {
    ScmType    string            `bson:"scm_type" json:"scm_type" validate:"required"`
    ScmURI     string            `bson:"scm_uri" json:"scm_uri" validate:"required"`
    Name       string            `bson:"name" json:"name" validate:"required"`
    ID         string            `bson:"id" json:"id"`
    JobCounter int               `bson:"job_counter" json:"job_counter"`
    Config     map[string]string `bson:"config" json:"config"`
}

We can use all the validators defined here https://godoc.org/gopkg.in/bluesuncorp/validator.v5#hdr-Baked_In_Validators_and_Tags

It's possible to create custom validator if necessary.

I use the package reflect to generate friendly error messages.

julienvey commented 9 years ago

LGTM but it needs to be rebased to be merged