This is a creation in Article, where the information may have evolved or changed.
The Go language function is passed as a parameter, and now I feel almost the same as C + +. It's very flexible.
Import "FMT" import "Time" Func goFunc1 (f func ()) { go f ()}func GoFunc2 (f func (interface{}), I interface{}) { go f ( i)}func gofunc (f interface{}, args ... interface{}) { If Len (args) > 1 { go f. (Func (... interface{})) (args) } else If Len (args) = = 1 { go f. (Func (interface{})) (Args[0]) } else { go f. (func ()) () } }func F1 () { fmt. Println ("F1 done")}func F2 (i interface{}) { fmt. Println ("F2 done", i)}func f3 (Args ... interface{}) {fmt. Println ("F3 done", args)}func main () { goFunc1 (F1) GoFunc2 (F2, +) Gofunc (F1 ) gofunc (F2, "xxxx" ) Gofunc (F3, "Hello", "World", 1, 3.14) time . Sleep (5 * time. Second)}
F1 done
F2 done 100
F1 done
F2 done xxxx
F3 done [[Hello World 1 3.14]]