Say I have a struct that I bind json param data to like
type User struct {
FirstName string `json:"firstName"`
}
The attribute FirstName has to be capitalized so that the json values can be binded to the struct.
But I also want to create an interface to accept any struct that has a FirstName like attribute. Since FirstName is already capitalized and taken, I have to name the method something else.
type NameInterface interface {
FirstName() string // nope
FirstNameValue() string // maybe?
}
But it seems really weird to have to add a helper function for each attribute on all my json structs just so they can work with an interface. Is there something I'm misunderstanding or a programming pattern I'm missing? What is the best way to get a json struct to work with interfaces in go?
More (what I am trying to do):
I want to parse json params that are coming from my controllers into structs. And then pass that struct data into filters which then run sql commands to filter data based on the params data. I wanted to use interfaces so I can pass in structs created from different sources into my filters.