I have a go struct which I'm using for my POST of an entity
type Student struct {
ID string `json:"id" firestore:"id"`
Name string `json:"name" validate:"required" firestore:"name"`
}
From the POST body request I can send body as
{
"id" : 123,
"name" : "Student Name"
}
I want to implement a functionality where the request should fail while doing the validation saying "id" field in POST body is not allowed.
As I'm planning to reuse the same struct for GET I'm unable to skip the "id" in json marshalling and unmarshalling.
Is there any struct tag like allowed:true or false ?
I tried to skip the json validation but I want to reuse the same struct i was unable to proceed.
In the code logic i can just every time override it to empty value but it doesn't seem to be good way to add custom logic for updating the fields after converting into object.
Saw various validate struct tag but didn't find any that will match the use case