I have this
var Map = map[string]Model{}
var (
mtx sync.Mutex
people Map
)
I am getting this error:
Is there any way of referencing the type of the Map, something like this:
var (
mtx sync.Mutex
people reflect.Type(Map) // <<< ?
)
or should I just resort to declare the type like so:
type Map map[string]Model
and the initializing the map like I do on line 54? I was just trying to initialize the map in the file without having to do it in the Init func.
I'm not sure I understood your problem but you can do something like this:
var Map = map[string]Model{}
var (
mtx sync.Mutex
people = Map
)
That way people
is initialized as same as Map
.
You can use map literal to initialize map:
type Model struct {}
var people = map[string]Model{
"Foo": Model{},
"Bar": Model{},
}
I think you want to use something like
type Model struct{}
type ModelMap map[string]Model
var (
mtx sync.Mutex
people = ModelMap{}
)