This commit is contained in:
loveuer
2026-01-28 10:28:13 +08:00
parent 507a67e455
commit 3ee0c9c098
29 changed files with 2852 additions and 0 deletions

28
tool/ctx.go Normal file
View File

@@ -0,0 +1,28 @@
package tool
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]
}
ctx, _ = context.WithTimeout(ctx, time.Duration(second) * time.Second)
return ctx
}