mirror of
https://github.com/TECHNOFAB11/powerproto.git
synced 2026-02-02 17:35:08 +01:00
feat(*): support perComandTimeout & variables in options
Signed-off-by: storyicon <yuanchao@bilibili.com>
This commit is contained in:
parent
7b2c0762d4
commit
15047711a9
15 changed files with 302 additions and 122 deletions
|
|
@ -16,12 +16,31 @@ package consts
|
|||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type debugMode struct{}
|
||||
type dryRun struct{}
|
||||
type ignoreDryRun struct{}
|
||||
type disableAction struct{}
|
||||
type perCommandTimeout struct{}
|
||||
|
||||
func GetContextWithPerCommandTimeout(ctx context.Context) (context.Context, context.CancelFunc) {
|
||||
val := ctx.Value(perCommandTimeout{})
|
||||
if val == nil {
|
||||
return ctx, func() {}
|
||||
}
|
||||
duration, ok := val.(time.Duration)
|
||||
if !ok {
|
||||
return ctx, func() {}
|
||||
}
|
||||
return context.WithTimeout(ctx, duration)
|
||||
}
|
||||
|
||||
// WithPerCommandTimeout is used to inject per command timeout
|
||||
func WithPerCommandTimeout(ctx context.Context, timeout time.Duration) context.Context {
|
||||
return context.WithValue(ctx, perCommandTimeout{}, timeout)
|
||||
}
|
||||
|
||||
// WithDebugMode is used to set debug mode
|
||||
func WithDebugMode(ctx context.Context) context.Context {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue