我正在使用谷歌从我的gcp获取一些信息。我需要设置超时,因为请求花费的时间太长。我试图像这样设置它idtoken.NewClient Timeout: time.Second * 10, Transport: http.DefaultTransport, } options := idtoken.WithHTTPClient(netClient) // client is a http.Client that automatically adds an "Authorization" header // to any requests made. client, err := idtoken.NewClient(ctx, targetURL, options)但我得到以下错误:idtoken.NewClient: transport/http: WithHTTPClient passed to NewTransport我不知道如何设置此选项
1 回答
海绵宝宝撒
TA贡献1809条经验 获得超8个赞
当函数接受上下文时,它应该优雅地处理其取消。这意味着,您可以使用 WithTimeout 包装上下文,以便在给定的持续时间后取消它,例如:
timeout, cancel := context.WithTimeout(ctx, 10 * time.Second)
defer cancel()
client, err := idtoken.NewClient(timeout, targetURL, options))
- 1 回答
- 0 关注
- 121 浏览
添加回答
举报
0/150
提交
取消
