type IntegerFilter struct {
op string
value int64
match func(int64, int64) bool
}
是个函数类型,参数和返回值都写清楚了
golang中,函数本身也是个一种值类型。
另外golang是支持闭包的,也就是说可以在函数中定义函数,内层函数可以访问外层函数的变量。
运行一下下面这个例子,你就懂了。
// hello project main.go
package main
import "fmt"
func hello() {
fmt.Println("hello")
}
func helloTo(name string) int {
fmt.Println("hello, ", name)
return 0
}
func main() {
var a func()
var b func(string) int
a = hello
a()
b = helloTo
fmt.Println(b("world"))
b = func(name string) int {
a()
fmt.Println(name)
return 1
}
fmt.Println(b("world"))
}