Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Passing a function as a parameter - Callback function

As it is right now, the run function can only accept callback functions without any parameter

package main

import (
	"fmt"
)

func main() {
	run(hello)
	run(world)
}

func hello() {
	fmt.Println("Hello")
}

func world() {
	fmt.Println("World!")
}

func run(f func()) {
	f()
}