I can't get real data from context.Get by go1.8
zhangliyuan7 opened this issue · 2 comments
In the process of using this package, I found that when using the Context.Get method of context to get some data in the HTTP Request, data[r] can't get the request information always. After testing, I found that the HTTPRequest pointer is different to the key of Data[]. The key does not match, this problem did not occur in go1.6, BUT go1.8 has this problem, what happened in the end caused this problem?
CODE
data = make(map[*http.Request]map[interface{}]interface{})func Get(r *http.Request, key interface{}) interface{} {
mutex.RLock()
fmt.Printf("%p\n",r)
fmt.Println("[debug]---------\n",data,"[debug]-----------\n",data[r])
if ctx := data[r]; ctx != nil {
value := ctx[key]
mutex.RUnlock()
return value
}
mutex.RUnlock()
return nil
}
THIS IS MY TEST RESULT>
2018/08/09 10:51:48 ### GET [::1]:48878 localhost:9003 /asset/owner ###
pointer :0xc42000ed30
[debug]--------- map[0xc4201dfc00:map[user:{ jackson jacksonZ@xxx.com} token:MTUzMzc4MDYxNXxEdi1CQkFFQ180SUFBUXdCRUFBQU5mLUNBQUVGZEc5clpXNEdjM1J5YVc1bkRDSUFJRFF5WTJJMFpUa3pZemxoTjJFNE1EY3paVFJqTjJReVpHRmpaVGMzTXpGa3yTiUR-1SH6BOxLrBwS7ge8kMAjRq7xCtB68qCtnBtOoA==]]
[debug]--------- map[]
1.6 the key same to pointer