I am using gorm v1 and gorilla/mux (REST API)
let's say I have
type User struct{
A string
B int
C int
.
.
Z string
}
Fields from A-H are mandatory and have a few other validations on them like
min/max size
no spaces
etc
Now, If I have a request
PATCH: api/v1/user/1
Body: {C:10}
How do I figure out if C was given as body in my API endpoint so that I can validate C (or any given field)
should I be doing this with a lot of if's and switch cases?
You can do this via go-playground/validator. If you don't wanna use external library, then you'll have to use reflect package, that's what essentially the validator package does as well.