I am trying to create a struct with values of other structs. For example a Filter
:
type ForSaleFilter struct {
Search string
}
type JobFilter struct {
JobType string
}
type Filter struct {
ForSale ForSaleFilter
Jobs JobFilter
}
I can't seem to figure out a better way to create the struct than this long line of code:
filter := Filter{ForSale: ForSaleFilter{Search: "cool stuff"}}
Is there a better way I can create this? Something like
filter := Filter{ForSale{Search: "cool stuff"}}
would be ideal. Maybe I could restructure my structs to do this?
Declare a variable for basic types, or for a struct that contains only basic types, the variable is also initialized in Go.
Thus, after declaration, it can be used immediately.
var filter Filter
filter.ForSale.Search = "cool stuff"
or
filter := Filter{}
filter.ForSale.Search = "cool stuff"