Documentation ¶
Overview ¶
Package executioncontext provides context helper function so set and get execution flags
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearFlag ¶
ClearFlag returns a new Context that no longer carries flag.
Example ¶
package main import ( "context" "fmt" "github.com/bradishungry/go-api-learning/pkg/executioncontext" ) func main() { ctx := context.Background() ctx = executioncontext.WithFlag(ctx, executioncontext.LIVE) ctx = executioncontext.WithFlag(ctx, executioncontext.REPLAY) ctx = executioncontext.ClearFlag(ctx, executioncontext.LIVE) fmt.Printf("%v\n", executioncontext.Has(ctx, executioncontext.LIVE)) fmt.Printf("%v\n", executioncontext.Has(ctx, executioncontext.REPLAY)) }
Output: false true
func Has ¶
has returns the bool value based on flag occurrence in context.
Example ¶
package main import ( "context" "fmt" "github.com/bradishungry/go-api-learning/pkg/executioncontext" ) func main() { ctx := context.Background() fmt.Printf("%v\n", executioncontext.Has(ctx, executioncontext.LIVE)) ctx = executioncontext.WithFlag(ctx, executioncontext.LIVE) fmt.Printf("%v\n", executioncontext.Has(ctx, executioncontext.LIVE)) }
Output: false true
func ToggleFlag ¶
ToggleFlag returns a new Context with toggled flag.
Example ¶
package main import ( "context" "fmt" "github.com/bradishungry/go-api-learning/pkg/executioncontext" ) func main() { ctx := context.Background() ctx = executioncontext.WithFlag(ctx, executioncontext.LIVE) ctx = executioncontext.ToggleFlag(ctx, executioncontext.REPLAY) fmt.Printf("%v\n", executioncontext.Has(ctx, executioncontext.LIVE)) fmt.Printf("%v\n", executioncontext.Has(ctx, executioncontext.REPLAY)) }
Output: true true
func WithFlag ¶
WithFlag returns a new Context that carries flag.
Example ¶
package main import ( "context" "fmt" "github.com/bradishungry/go-api-learning/pkg/executioncontext" ) func main() { ctx := context.Background() ctx = executioncontext.WithFlag(ctx, executioncontext.LIVE) fmt.Printf("%v", executioncontext.Has(ctx, executioncontext.LIVE)) }
Output: true
Types ¶
type Flag ¶
type Flag uint8
Flag type
Execution context flags
func FromContext ¶
FromContext returns the slice of flags stored in ctx
Example ¶
package main import ( "context" "fmt" "github.com/bradishungry/go-api-learning/pkg/executioncontext" ) func main() { ctx := context.Background() flags := executioncontext.FromContext(ctx) fmt.Printf("%v\n", flags) ctx = executioncontext.WithFlag(ctx, executioncontext.LIVE) ctx = executioncontext.WithFlag(ctx, executioncontext.REPLAY) flags = executioncontext.FromContext(ctx) fmt.Printf("%v\n", flags) }
Output: 0 3
Click to show internal directories.
Click to hide internal directories.