I have found no way to declare variables immediately above a select case.
Like in http://play.golang.org/p/RublOzUdhR the “input” variable seems to have to be declared above the for-loop, not just after select or even “best” just above the case.
It seems like variables input to by a channel in a case and used only within the case has to be more “global” than really necessary? What are the lexical scoping rules here?
It needs to be declared before (i.e., outside) the for loop, because you expect it to be in scope in the fmt.Println after the for loop. But it’s not actually used, because you are declaring other “input” variables in the select cases (shadowing). Also, you were adding unnecessary braces in the cases.