एक closure एक function हो जसले आफ्नो surrounding scope बाट variables लाई reference गर्छ, तिनीहरूलाई "close over" गर्छ — यो function enclosing function return भएपछी पनि ती variables मा access राखता। Go functions first-class values हुन्, जसले closures लाई सामान्य र शक्तिशाली tool बनाउँछ।
एक आधारभूत closure
{
count :=
{
count++
count
}
}
counter := makeCounter()
fmt.Println(counter())
fmt.Println(counter())
other := makeCounter()
fmt.Println(other())
