Golang中函数的应用
package _func
import (
"fmt"
"math/rand"
"testing"
"time"
)
func returnMulitiValue()(int,int){
return rand.Intn(10),rand.Intn(20)
}
func TimeSpent (inner func(op int) int) func(op int) int{
return func(n int) int {
start := time.Now()
ret := inner(n)
fmt.Println("Time Spent:",time.Since(start).Seconds())
return ret
}
}
func slowFun(op int) int {
time.Sleep(time.Second*1)
return op
}
func TestFn(t *testing.T) {
a,b := returnMulitiValue()
t.Log(a,b)
tsSF := TimeSpent(slowFun)
t.Log(tsSF(10))
}