Golang: Nest Function
To define a Function inside a function, declare a variable and give it a function value. Like this:
var f = func(params) return_type {body}
or use the variable shortcut:
f := func(params) return_type {body}
package main import "fmt" func main() { // this is a function, inside the function main var ff = func(x int) int { return x + 1 } fmt.Println(ff(3)) // 4 }