I have a Go package that has a large number of (auto-generated) models:
Tax2001_1
Tax2001_2
Tax2001_3
...
Tax2020_1
Each is defined like this:
func NewTax2011_1() *Tax2011_1 {
return &Tax2011_1 { ... }
}
I want to access them depending on a value (timestamp) that is only known at runtime. So I am trying to put the model constructors into a map:
package tax
type TaxModel interface {
Calculate()
}
var taxModels = make(map[string]func() *TaxModel)
func init() {
...
taxModels["2011_1"] = NewTax2011_1
taxModels["2011_2"] = NewTax2011_2
...
}
The above code is not correct:
cannot use NewTax2011_1 (type func() *Tax2011_1) as type func() *TaxModel in assignment
Any hint how to achieve that?