rcrowley / go-tigertonic

A Go framework for building JSON web services inspired by Dropwizard
Other
997 stars 79 forks source link

Dropwizard-like validation #24

Open wadey opened 10 years ago

wadey commented 10 years ago

Dropwizard has a nice integration with Hibernate Validator that makes it easy to give good error messages when the user provides an incorrect JSON payload (e.g. missing a key).

See: http://dropwizard.codahale.com/manual/core/#validation

wadey commented 10 years ago

One way I envision this is being able to add some additional tags to my request structs, like so:

type MyRequest struct {
    ID   string `json:"id" validate:"notempty"`
    Name string `json:"name"`
}

If a POST request came in with a MyRequest body that didn't have an ID, then it would return a 400 with some information about why.

I have been searching to see if any go libraries exist that do this, but I haven't found anything yet.

rcrowley commented 10 years ago

This seems like a good use of tags. I like it.

bigkevmcd commented 10 years ago

http://robteix.com/blog/2014/04/29/package-validate/

wadey commented 10 years ago

@bigkevmcd Perfect! This package is exactly what I wanted.

pjvds commented 8 years ago

Just for reference, the link @bigkevmcd provided is dead. Here is the new one: https://github.com/go-validator/validator