Fetch value from net/context in Golang
<p>I am using Golang net/context package for passing on the ID's wrapped in a context object from one service to another. I am able to pass the context object successfully but to actually retrieve the value of a particular key, the context.Value(key) always returns a nil. I am not sure why, but this is what I have done so far:</p>

<pre><code>if ctx != nil {
        fmt.Println(ctx)
        fmt.Println("Found UUID, forwarding it")

        id, ok := ctx.Value(0).(string)  // This always returns a nil and thus ok is set to false
        if ok {
            fmt.Println("id found %s", id)
            req.headers.Set("ID", id)
        }
    }  
</code></pre>

<p>ctx is of the type context.Context and on printing it I get:</p>

<pre><code>context.Background.WithValue(0, "12345")
</code></pre>

<p>I am interested in fetching the value "12345" from the context. From the Golang net/context documentation (<a href="https://blog.golang.org/context" rel="nofollow">https://blog.golang.org/context</a>) , the Value() takes in a key of interface{} type and returns a interface{} and hence I typecast is to .(string). Could anyone help with this ?</p>