Karthic Rao
Karthic Rao

Reputation: 3754

Google Cloud Storage Client App error using Go Runtime Google App Engine

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 ??

Upvotes: 4

Views: 1522

Answers (2)

mbonnin
mbonnin

Reputation: 7022

You need to update from appengine to google.golang.org/appengine as described there: https://github.com/golang/oauth2/#app-engine

Upvotes: 2

icza
icza

Reputation: 417412

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},
}

Upvotes: 5

Related Questions