How to reduce number of parameters in go nested function calls -


i have go calltree structured follows:

// state common struct shared among "instances" of mytype - simulating member variables interface (s mytype) run(state *state){ // called outside   // define goroutines fetch via http   httpcallback(){ // runs on every http response     parsedata(record, outputchan)   } } (s mytype) parsedata(rec []string, outputchan chan(interface{})){   // doesn't need "state" far   doidmapping(string)  }   doidmapping(key) {     return state.map[key]  } 

is there way of getting access map (which constant) without being forced pass "state" through httpcallback , goroutines above end in calling httpcallback?

this not bad clear code bad when comes testing. intermediate functions carry around struct pointer don't need depend on. did miss language design of go? :/

if of within single package can declare state @ package level , use everywhere. example;

package myhttpclient  import (     "allthatstuff" )  state state // not exported available everywhere in 'myhttpclient' externstate state // exported importing myhttpclient can myhttpclient.externstate 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

Maven Javadoc 'Cannot find default setter' and fails -