Is it possible to define a local variable in Go that can maintain its value from one function call to another? In C, we can do this using the reserved word static.<
static
You can do something like this
package main import ( "fmt" ) func main() { f := do() f() // 1 f() // 2 } func do() (f func()){ var i int f = func(){ i++ fmt.Println(i) } return }
Link on Playground https://play.golang.org/p/D9mv9_qKmN