优化逻辑
This commit is contained in:
23
internal/routes/standby_ctrl/duration.go
Normal file
23
internal/routes/standby_ctrl/duration.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package standby_ctrl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Duration 持续时长控制器
|
||||
func Duration(duration int64, play func(c context.Context) error) func(c context.Context) error {
|
||||
return func(c context.Context) error {
|
||||
zap.S().Infoln("待机持续时长控制器: ", duration)
|
||||
defer zap.S().Infoln("待机持续时长控制器结束: ", duration)
|
||||
|
||||
if duration > 0 {
|
||||
ctx, cancel := context.WithTimeout(c, time.Duration(duration)*time.Second)
|
||||
defer cancel()
|
||||
c = ctx
|
||||
}
|
||||
|
||||
return play(c)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user