go-tigertonic icon indicating copy to clipboard operation
go-tigertonic copied to clipboard

Dropwizard-like validation

Open wadey opened this issue 11 years ago • 5 comments

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 avatar Aug 05 '13 19:08 wadey

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.

wadey avatar Nov 05 '13 23:11 wadey

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

rcrowley avatar Nov 05 '13 23:11 rcrowley

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

bigkevmcd avatar May 02 '14 22:05 bigkevmcd

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

wadey avatar May 02 '14 23:05 wadey

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

pjvds avatar Oct 26 '15 20:10 pjvds