this post was submitted on 03 Sep 2023
1 points (100.0% liked)

The Go Programming Language

1 readers
0 users here now

Ask questions and post articles about the Go programming language and related tools, events etc.

founded 1 year ago
MODERATORS
 
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!

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here