I have a go Calltree which is structured as follows:
// state is a common struct shared among all "instances" of MyType - simulating member variables for an Interface
(s MyType) Run(state *State){ // called from outside
// define goroutines that fetch something via http
HTTPCallback(){ // runs on every http response
parseData(record, outputChan)
}
}
(s MyType) parseData(rec []string, outputChan chan(interface{})){
// doesn't need anything from "state" so far
doIdMapping(string)
}
doIdMapping(key) {
return state.Map[key]
}
Is there a way of getting access to the Map (which is completely constant) without being forced to pass the "state" through HTTPCallback and all the goroutines above which end up in calling HTTPCallback?
This is not only bad for a clear code but also is bad when it comes to testing. All the intermediate functions carry around that struct pointer which they don't even need to depend on. Did I miss something about the language design of go? :/