context的WithTimeout实现调用自定义函数超时处理
func UploadContent(content, objectName string) chan error {
errCh := make(chan error, 1)
return errCh
}
func UploadFromString(content, objectName string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(time.Millisecond * 5000))
defer cancel()
select {
case <- this.UploadContent(content, objectName):
return
case <- ctx.Done():
fmt.Println(“Upload Oss Timeout"”)
return
}
}