Callback in Golang, I'm trying to pass a function square (callback) and then a number to a function where the function square will return square of any number but it shows an error, 'function body missing'

package main

import “fmt”

func main() {

fmt.Println(squareMinusNum(square, 8))

}

func square (int num) int {

return num*num

}

func squareMinusNum (f(int num) int, num int) int{

x:= f(num)-num

return x

}

// https://play.golang.org/p/WGu2tHIL3Uq

1 Like

Hey Sajir!

You just had a couple of easy fixes. In go the type comes after the name, for example func(num int) instead of func(int num), which is what you had.

https://play.golang.org/p/XexKFyWeL6l

Let me know if you have any more questions about this.