Functional literals

A functional literal just represents an anonymous function. You can assign functional literal to a variable: package main import ( "fmt" ) func main() { f := func() { fmt.Println("Hello, भारत!") } f() } Or invoke functional literal directly (Please notice the () at the end of functional literal): package main import ( "fmt" ) func main() { func() { fmt.Println("Hello, भारत!") }() } The above 2 programs both output “Hello, भारत!”. [Read More]

Go - init function

There is a init() function, as the name suggests, it will do some initialization work, such as initializing variables which may not be expressed easily, or calibrating program state. A file can contain one or more init() functions, as shown here: package main import "fmt" var global int = 0 func init() { global++ fmt.Println("In first Init(), global is: ", global) } func init() { global++ fmt.Println("In Second Init(), global is: ", global) } func main() { fmt. [Read More]