Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 697
Karthic Rao Avatar asked Mar 17 '23 18:03

Karthic Rao


2 Answers

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},
}
like image 65
icza Avatar answered Apr 10 '23 10:04

icza


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

like image 20
mbonnin Avatar answered Apr 10 '23 10:04

mbonnin