Im trying the example code from this link and trying to do operations on Google Cloud Storage using Google Cloud Storage Client App from Go runtime , But the following part in the sample code is giving the error "cannot use c (type "appengine".Context) as type context.Context in function argument: "appengine".Context does not implement context.Context (missing Deadline method)"
c := appengine.NewContext(r)
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: c},
},
}
Whats the issue here ?? How can i solve this ??
The error message clearly states that you try to pass a value of type appengine.Context
where the expected type is context.Context
.
The google.AppEngineTokenSource()
function expects a value of type context.Context
and not the one you pass (which is of type appengine.Context
).
You can create such Context
with the function:
cloud.NewContext(projID string, c *http.Client)
This is how I would do it:
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},
}
You need to update from appengine
to google.golang.org/appengine
as described there: https://github.com/golang/oauth2/#app-engine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With