This is an automated archive.

The original was posted on /r/golang by /u/Spcbrn on 2023-09-03 17:57:07+00:00.


Hi fellow gophers,

I’ve been playing with validator and gin-gonic for quite some time and found myself having to copy-paste my structs/forms whenever I needed the slightest validation difference.

Most common case is when I’m writing create and update endpoints for an object.I would want the create object validation to have most of its fields mandatory but not in the case of an update.

Some code will surely help you understand what I’m talking about: go type CreateCarForm struct { Manufacturer string json:“manufacturer” binding:“required” Model stringjson:“model” binding:“required” FuelType stringjson:“fuel_type” binding:“required,oneof=diesel electricity gasoline”} type UpdateCarForm struct { Manufacturer stringjson:“manufacturer” Model stringjson:“model” FuelType stringjson:“fuel_type” binding:“oneof=diesel electricity gasoline” }

I am missing something or Is it the way to go? (pun intended)

Thanks!