1 回答
 
                    
                    TA贡献1856条经验 获得超17个赞
- 来自的请求无法 - google/oauth2被 追踪- httptrace。您- ClientWrapper传递的 with- context.WithValue将在这里被忽略,并且 oauth2 有它自己的 http.Client,它只是使用from context.Value的- Transport方法。- *http.Client
- 来自 androidpublisher 的请求可以通过 httptrace 跟踪,如下所示: 
ctx := httptrace.WithClientTrace(context.Background(), clientWrapperTrace)r, err := c.VerifyProduct(ctx, packageName, productID, token)
- 如果您只想计算请求,我认为覆盖 - http.Client.Transport是一种简单的方法。
type TraceTransport struct {
}
func (t *TraceTransport) RoundTrip(req *http.Request) (*http.Response, error) {
fmt.Printf("RoundTrip hook %v\n", req.URL)
return http.DefaultTransport.RoundTrip(req)
}
func NewClientTrace(jsonKey []byte) (*Client, error) {
cli := &http.Client{Transport: &TraceTransport{}}
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, cli)
// ...
service, err := androidpublisher.NewService(ctx, option.WithHTTPClient(conf.Client(ctx)))
// ....
}
- 1 回答
- 0 关注
- 257 浏览
添加回答
举报
