context.WithValue context.WithTimeout

func tctx() {
    f := func() context.Context {
        ctx := context.TODO()
        ctx = context.WithValue(ctx, "k", "v")
        myprint(ctx.Value("k"))
        return ctx
    }
    ctx := f()
    ctx, _ = context.WithTimeout(ctx, 32*time.Second)

    myprint("2", ctx.Value("k"))

}
func myprint(l ...interface{}) {
    fmt.Println(l...)
}
 
 
posted @ 2022-07-27 20:09  papering  阅读(115)  评论(0编辑  收藏  举报