Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clone ¶
Clone creates a new Context object but inherits values from the base context object.
Example ¶
package main import ( "context" "fmt" "github.com/izumin5210/clonectx" ) func main() { debug := func(ctx context.Context) { fmt.Println( "user_id: ", ctx.Value("user_id"), "\t", "request_id: ", ctx.Value("request_id"), "\t", "error: ", ctx.Err(), ) } baseCtx, cancel := context.WithCancel(context.Background()) baseCtx = context.WithValue(baseCtx, "user_id", 123) baseCtx = context.WithValue(baseCtx, "request_id", "7de4f345-8a68-47bc-a1df-90299f95d753") newCtx := clonectx.Clone(baseCtx) cancel() debug(baseCtx) debug(newCtx) }
Output: user_id: 123 request_id: 7de4f345-8a68-47bc-a1df-90299f95d753 error: context canceled user_id: 123 request_id: 7de4f345-8a68-47bc-a1df-90299f95d753 error: <nil>
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.