gpt4 book ai didi

google-app-engine - 使用 Go Runtime Google App Engine 的 Google Cloud Storage Client App 错误

转载 作者:IT王子 更新时间:2023-10-29 00:39:31 26 4
gpt4 key购买 nike

我正在尝试来自 this link 的示例代码并尝试对其进行操作Google Cloud Storage 使用来自 Go 运行时的 Google Cloud Storage 客户端应用程序,但示例代码中的以下部分给出了错误“无法使用 c(类型“appengine”。上下文)作为类型上下文。函数中的上下文参数: “appengine”。Context 没有实现 context.Context(缺少 Deadline 方法)“

c := appengine.NewContext(r)
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: c},
},
}

这里有什么问题??我该如何解决这个问题??

最佳答案

错误消息明确指出您尝试传递类型为 appengine.Context 的值,而预期类型为 context.Context

google.AppEngineTokenSource()函数需要一个 context.Context 类型的值而不是您传递的那个(属于 appengine.Context 类型)。

您可以使用以下函数创建这样的Context:

cloud.NewContext(projID string, c *http.Client)

我会这样做:

c := appengine.NewContext(r)
hc := &http.Client{}
ctx := cloud.NewContext(appengine.AppID(c), hc)
hc.Transport = &oauth2.Transport{
Source: google.AppEngineTokenSource(ctx, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: c},
}

关于google-app-engine - 使用 Go Runtime Google App Engine 的 Google Cloud Storage Client App 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29010718/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com