on-internet
← Community

How to validate allowed fields in json body in go validation

Stack Overflow ·

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 j

Comments

Sign in or sign up to comment and upvote.

No comments yet.