本文整理汇总了Golang中golang.org/x/oauth2/google.AppEngineTokenSource函数的典型用法代码示例。如果您正苦于以下问题:Golang AppEngineTokenSource函数的具体用法?Golang AppEngineTokenSource怎么用?Golang AppEngineTokenSource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AppEngineTokenSource函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handlePut
func handlePut(res http.ResponseWriter, req *http.Request) {
ctx := appengine.NewContext(req)
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(ctx, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: ctx},
},
}
cctx := cloud.NewContext(appengine.AppID(ctx), hc)
rdr, hdr, err := req.FormFile("form-upload-file")
if err != nil {
http.Error(res, "ERROR RECEIVING FILE: "+err.Error(), 500)
return
}
writer := storage.NewWriter(cctx, bucketName, hdr.Filename)
io.Copy(writer, rdr)
err = writer.Close()
if err != nil {
http.Error(res, "ERROR WRITING TO BUCKET: "+err.Error(), 500)
return
}
}
示例2: StartupHandler
func StartupHandler(w http.ResponseWriter, r *http.Request) {
if len(Config) == 0 {
c := appengine.NewContext(r)
client := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, storage.ScopeReadOnly),
Base: &urlfetch.Transport{
Context: c,
},
},
}
bucket, _ := file.DefaultBucketName(c)
ctx := cloud.NewContext("davine-web", client)
rc, err := storage.NewReader(ctx, bucket, "config.yaml")
if err != nil {
c.Errorf("error reading config: %v", err.Error())
return
}
configFile, err := ioutil.ReadAll(rc)
rc.Close()
if err != nil {
c.Errorf("error reading config: %v", err.Error())
return
}
c.Infof("loaded config file: %v", configFile)
yaml.Unmarshal(configFile, &Config)
c.Infof("loaded config struct: %v", Config)
}
}
示例3: httpClient
// httpClient returns an authenticated http client, suitable for App Engine.
func httpClient(c context.Context, scopes ...string) *http.Client {
t := &oauth2.Transport{
Source: google.AppEngineTokenSource(c, scopes...),
Base: &urlfetch.Transport{Context: c},
}
return &http.Client{Transport: t}
}
示例4: handler
func handler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
transport := &oauth2.Transport{
Source: google.AppEngineTokenSource(c, "https://spreadsheets.google.com/feeds"),
Base: &urlfetch.Transport{Context: c},
}
client := &http.Client{Transport: transport}
spreadsheetsID := "1QwybKPlmYFhFa5CSZqfwsmQDIPTfagMtvQ0C3CA5xwY"
sheetID := "1560292823" // gid=sheetID
resp, err := client.Get("https://docs.google.com/spreadsheets/d/" + spreadsheetsID + "/gviz/tq?gid=" + sheetID)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer resp.Body.Close()
contents, err := ioutil.ReadAll(resp.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprintf(w, "%s\n", string(contents))
}
示例5: insert
func insert(datasetId string, tableName string, ctx context.Context, json map[string]bigquery.JsonValue) {
client := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(ctx, bigquery.BigqueryScope),
Base: &urlfetch.Transport{Context: ctx},
},
}
bq, err := bigquery.New(client)
if err != nil {
fmt.Errorf("could not create service: %v", err)
return
}
appID := appengine.AppID(ctx)
request := new(bigquery.TableDataInsertAllRequest)
rows := make([]*bigquery.TableDataInsertAllRequestRows, 1)
rows[0] = new(bigquery.TableDataInsertAllRequestRows)
rows[0].Json = json
request.Rows = rows
_, errr := bq.Tabledata.InsertAll(appID, datasetId, tableName, request).Do()
if errr != nil {
fmt.Errorf("could not insert: %v", err)
return
}
}
示例6: Start
func (cloud *CloudStore) Start() error {
if cloud.Bucket == "" {
return InvalidBucket
}
if cloud.Context == nil {
return InvalidGoogleContext
}
client := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(cloud.Context, storage.DevstorageFullControlScope),
Base: &urlfetch.Transport{Context: cloud.Context},
},
}
service, err := storage.New(client)
if err != nil {
log.Printf("Unable to get storage service %v", err)
return err
}
cloud.service = service
if _, err := service.Buckets.Get(cloud.Bucket).Do(); err == nil {
log.Printf("Got storage bucket %v %v", cloud.Bucket, err)
} else {
if _, err := service.Buckets.Insert(cloud.Project, &storage.Bucket{Name: cloud.Bucket}).Do(); err == nil {
log.Printf("Created bucket: %v", cloud.Bucket)
} else {
return err
}
}
return nil
}
示例7: datasets
// datasets returns a list with the ids of all the Big Query datasets visible
// with the given context.
func datasets(ctx context.Context) ([]string, error) {
// create a new authenticated HTTP client over urlfetch.
client := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(ctx, bigquery.BigqueryScope),
Base: &urlfetch.Transport{Context: ctx},
},
}
// create the BigQuery service.
bq, err := bigquery.New(client)
if err != nil {
return nil, fmt.Errorf("could not create service: %v", err)
}
// obtain the current application id, the BigQuery id is the same.
appID := appengine.AppID(ctx)
// prepare the list of ids.
var ids []string
datasets, err := bq.Datasets.List(appID).Do()
if err != nil {
return nil, fmt.Errorf("could not list datasets for %q: %v", appID, err)
}
for _, d := range datasets.Datasets {
ids = append(ids, d.Id)
}
return ids, nil
}
示例8: handlerContainer2
func handlerContainer2(w http.ResponseWriter, r *http.Request) {
ctx := appengine.NewContext(r)
client := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(ctx, bigquery.BigqueryScope),
Base: &urlfetch.Transport{Context: ctx},
},
}
bq, err := bigquery.New(client)
if err != nil {
fmt.Errorf("%v", err)
}
key := datastore.Key{}
c := Container2{
Hoge: Hoge{Name: "hoge", Age: 28},
Key: &key,
}
schema, err := ironmole.BuildTableSchema(&c)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = ironmole.CreateTable(bq, "cp300demo1", "go2bq", "Container2", schema)
if err != nil {
log.Errorf(ctx, "%v", err)
}
}
示例9: handler
// handler is the main demo entry point that calls the GCS operations.
func handler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
http.NotFound(w, r)
return
}
c := appengine.NewContext(r)
if bucket == "" {
var err error
if bucket, err = file.DefaultBucketName(c); err != nil {
log.Errorf(c, "failed to get default GCS bucket name: %v", err)
return
}
}
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, storage.ScopeFullControl),
// Note that the App Engine urlfetch service has a limit of 10MB uploads and
// 32MB downloads.
// See https://cloud.google.com/appengine/docs/go/urlfetch/#Go_Quotas_and_limits
// for more information.
Base: &urlfetch.Transport{Context: c},
},
}
ctx := cloud.NewContext(appengine.AppID(c), hc)
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
fmt.Fprintf(w, "Demo GCS Application running from Version: %v\n", appengine.VersionID(c))
fmt.Fprintf(w, "Using bucket name: %v\n\n", bucket)
d := &demo{
c: c,
w: w,
ctx: ctx,
}
n := "demo-testfile-go"
d.createFile(n)
d.readFile(n)
d.copyFile(n)
d.statFile(n)
d.createListFiles()
d.listBucket()
d.listBucketDirMode()
d.defaultACL()
d.putDefaultACLRule()
d.deleteDefaultACLRule()
d.bucketACL()
d.putBucketACLRule()
d.deleteBucketACLRule()
d.acl(n)
d.putACLRule(n)
d.deleteACLRule(n)
d.deleteFiles()
if d.failed {
io.WriteString(w, "\nDemo failed.\n")
} else {
io.WriteString(w, "\nDemo succeeded.\n")
}
}
示例10: getCloudContext
func getCloudContext(gae context.Context) context.Context {
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(gae, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: gae},
},
}
return cloud.NewContext(appengine.AppID(gae), hc)
}
示例11: Generate
func (cfg *AppengineStoreConfig) Generate(c context.Context) files.FileStore {
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: c},
},
}
ctx := cloud.WithContext(c, appengine.AppID(c), hc)
return &AppengineStore{cfg, ctx}
}
示例12: newComputeService
// newComputeService returns a new Compute Engine API Client,
// to use with Google App Engine.
func newComputeService(c context.Context) (service *compute.Service, err error) {
client := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, compute.ComputeScope),
Base: &urlfetch.Transport{
Context: c,
},
},
}
return compute.New(client)
}
示例13: cloudAuthContext
// Get an auth context for logging RPC.
func cloudAuthContext(r *http.Request) (context.Context, error) {
c := appengine.NewContext(r)
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, logging.Scope),
Base: &urlfetch.Transport{Context: c},
},
}
return cloud.WithContext(c, appengine.AppID(c), hc), nil
}
示例14: NewClient
// NewClient returns an http.Client that can be used to create services from the
// Google APIs for Go library https://github.com/google/google-api-go-client.
// The scopes parameter is used to declare the OAuth 2
// scopes, e.g., storage.DevstorageFullControlScope.
func NewClient(c context.Context, scopes ...string) *http.Client {
return &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, scopes...),
// Note that the App Engine urlfetch service has a limit of 10MB uploads and
// 32MB downloads.
// See https://cloud.google.com/appengine/docs/go/urlfetch/#Go_Quotas_and_limits
// for more information.
Base: &urlfetch.Transport{Context: c},
},
}
}
示例15: cloudAuthContext
func cloudAuthContext(r *http.Request) (context.Context, error) {
c := appengine.NewContext(r)
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: c},
},
}
return cloud.WithContext(c, "rule110-go", hc), nil
}