Avatar ·

Removing fields from a struct or hiding them in JSON response in Go

Hi everyone! I'm new to Go and ran into this problem. I have a User struct that is used for storing user data in the database and for sending JSON responses via REST API. ```go type User struct { ID int `json:"id"` Username string `json:"username"` Email string `json:"email"` Password string `json:"password"` Role string `json:"role"` } ``` When I return a user in JSON (for example, after registration), I don't want to send the Password field and possibly the Role field (for regular users). But I don't want to create separate structs for each case — that leads to code duplication. I tried using `json:"-"` for the Password field, but then it will never be included in JSON, and I need it to