我正在使用谷歌從我的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 關注
- 105 瀏覽
添加回答
舉報
0/150
提交
取消