import (
"context"
"fmt"
"reflect"
)
type MyRequest struct {
Url string
Method string
Params map[string]interface{}
}
func main() {
params := make(map[string]interface{})
rootRequest := MyRequest{
Url: "https://localhost:8080/getinfo",
Method: "Post",
Params: params,
}
httpCtx := context.WithValue(context.Background(), "request", rootRequest)
value1 := httpCtx.Value("request")
fmt.Println(reflect.TypeOf(value1))
fmt.Println(value1.Url)
}
如上代码,fmt.Println(reflect.TypeOf(value1))
打印结果为main.MyRequest
,但是fmt.Println(value1.Url)
却会报错:
value1.Url undefined (type interface {} is interface with no methods)
有疑问加站长微信联系(非本文作者)

感谢