go 装饰器
go 装饰器实现统计函数运行时间
func TestDecorator(t *testing.T) {
fn := Timer(TimerTest)
fn()
}
func Timer(fn func()) func() {
return func() {
start_time := time.Now().Unix()
fn()
end_time := time.Now().Unix()
fmt.Println("func use time: ",end_time-start_time)
}
}
func TimerTest() {
fmt.Println("运行timerTest func")
time.Sleep(time.Second *2 )
}