feat: 🎉 完成基本功能
This commit is contained in:
28
internal/util/ctx.go
Normal file
28
internal/util/ctx.go
Normal file
@ -0,0 +1,28 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Timeout(seconds ...int) context.Context {
|
||||
second := 30
|
||||
if len(seconds) > 0 && seconds[0] > 0 {
|
||||
second = seconds[0]
|
||||
}
|
||||
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(second)*time.Second)
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
func TimeoutCtx(ctx context.Context, seconds ...int) context.Context {
|
||||
second := 30
|
||||
if len(seconds) > 0 && seconds[0] > 0 {
|
||||
second = seconds[0]
|
||||
}
|
||||
|
||||
timeout, _ := context.WithTimeout(ctx, time.Duration(second)*time.Second)
|
||||
|
||||
return timeout
|
||||
}
|
Reference in New Issue
Block a user