package main
import (
"fmt"
)
func main() {
funcWithCounter1 := funcWithCounter()
fmt.Println(funcWithCounter1())
fmt.Println(funcWithCounter1())
fmt.Println(funcWithCounter1())
funcWithCounter2 := funcWithCounter()
fmt.Println(funcWithCounter2())
fmt.Println(funcWithCounter2())
}
func funcWithCounter() func() int {
var counter int
return func() int {
// тут полезная работа
counter++
return counter
}
}