Documentation
¶
Overview ¶
Example ¶
package main import ( "context" "fmt" "github.com/rakunlabs/contextx" ) func main() { ctx := contextx.WithValue(context.Background(), "secret", "xxx") if v, ok := contextx.Value[string](ctx, "secret"); ok { fmt.Println("[" + v + "]") } ctx = contextx.WithValue(ctx, "another", "yyy", contextx.WithKey("customKey")) if v, ok := contextx.Value[string](ctx, "another"); ok { fmt.Println("[" + v + "]") } else { // expected not found fmt.Println("not found") } if v, ok := contextx.Value[string](ctx, "secret", contextx.WithKey("customKey")); ok { fmt.Println("[" + v + "]") } else { // expected not found fmt.Println("not found") } if v, ok := contextx.Value[string](ctx, "another", contextx.WithKey("customKey")); ok { // expected found fmt.Println("[" + v + "]") } }
Output: [xxx] not found not found [yyy]
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.