本文整理汇总了Golang中golang.org/x/oauth2/google.AppEngineTokenSource函数的典型用法代码示例。如果您正苦于以下问题:Golang AppEngineTokenSource函数的具体用法?Golang AppEngineTokenSource怎么用?Golang AppEngineTokenSource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AppEngineTokenSource函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
}
开发者ID:kaveenherath,项目名称:SummerBootCamp,代码行数:27,代码来源:storage.go
示例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)
}
}
开发者ID:vishnuvr,项目名称:davine,代码行数:30,代码来源:routes.go
示例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}
}
开发者ID:kleopatra999,项目名称:weasel,代码行数:8,代码来源:object.go
示例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))
}
开发者ID:basilboli,项目名称:POCZone,代码行数:28,代码来源:spreadsheet2json.go
示例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
}
}
开发者ID:etiiig,项目名称:bigquery,代码行数:27,代码来源:bigquery.go
示例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
}
开发者ID:smacken,项目名称:sprocess-cloudstorage,代码行数:31,代码来源:cloudstore.go
示例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
}
开发者ID:wuman,项目名称:golang-samples,代码行数:31,代码来源:app.go
示例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)
}
}
开发者ID:sinmetal,项目名称:ironmole,代码行数:31,代码来源:example.go
示例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")
}
}
开发者ID:rkazak,项目名称:distribution,代码行数:60,代码来源:app.go
示例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)
}
开发者ID:XiaonuoGantan,项目名称:gaefile,代码行数:9,代码来源:upload.go
示例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}
}
开发者ID:orian,项目名称:files,代码行数:10,代码来源:appengine.go
示例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)
}
开发者ID:ronoaldo,项目名称:aetools,代码行数:13,代码来源:compute.go
示例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
}
开发者ID:tomayac,项目名称:amphtml,代码行数:12,代码来源:errortracker.go
示例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},
},
}
}
开发者ID:drichardson,项目名称:appengine,代码行数:16,代码来源:client.go
示例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
}
开发者ID:matthewdu,项目名称:rule110-go,代码行数:12,代码来源:googlecloudstorage.go
示例16: ExampleAppEngineTokenSource
func ExampleAppEngineTokenSource() {
var req *http.Request // from the ServeHTTP handler
ctx := appengine.NewContext(req)
client := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(ctx, "https://www.googleapis.com/auth/bigquery"),
Base: &urlfetch.Transport{
Context: ctx,
},
},
}
client.Get("...")
}
开发者ID:Crosse,项目名称:oauth2,代码行数:13,代码来源:example_test.go
示例17: fileHandler
func fileHandler(c *gin.Context) {
username := c.Param("username")
title := c.Param("title")
filename := c.Param("fileName")
gaeContext := appengine.NewContext(c.Request)
hc := &http.Client{
Transport: &CloudStorageTransport{&oauth2.Transport{
Source: google.AppEngineTokenSource(gaeContext, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: gaeContext},
}},
}
bucketName := "balde_de_bits"
bucketFile := username + "/" + title + "/" + filename
log.Errorf(gaeContext, "ID ->>> %v", appengine.AppID(gaeContext))
log.Errorf(gaeContext, "File name ->>> %v", bucketFile)
ctx := cloud.NewContext(appengine.AppID(gaeContext), hc)
wc := storage.NewWriter(ctx, bucketName, bucketFile)
if strings.Contains(filename, "m3u8") {
wc.ContentType = "application/x-mpegURL"
wc.CacheControl = "max-age:0"
} else if strings.Contains(filename, "ts") {
wc.ContentType = "video/MP2T"
} else if strings.Contains(filename, "jpg") {
wc.ContentType = "image/jpeg"
}
defer wc.Close()
bytesWritten, err := io.Copy(wc, c.Request.Body)
if err != nil {
log.Errorf(gaeContext, "Writing to cloud storage failed. %v", err.Error())
c.JSON(200, gin.H{
"response": "< FAILED >",
})
return
}
log.Errorf(gaeContext, "Wrote < %v > bytes for file < %v >", bytesWritten, filename)
c.JSON(200, gin.H{
"response": "< worked >",
})
}
开发者ID:BearchInc,项目名称:http-streaming,代码行数:51,代码来源:main.go
示例18: handler
func handler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: c},
},
}
ctx := cloud.NewContext(appengine.AppID(c), hc)
d := &demo{
c: c,
w: w,
ctx: ctx,
}
d.listBucket()
}
开发者ID:Tanoemon,项目名称:atelier-sou-vue,代码行数:17,代码来源:server.go
示例19: shortenURL
// shortenURL returns a short URL which redirects to the provided url,
// using Google's urlshortener API.
func shortenURL(ctx context.Context, url string) (string, error) {
transport := &oauth2.Transport{
Source: google.AppEngineTokenSource(ctx, urlshortener.UrlshortenerScope),
Base: &urlfetch.Transport{Context: ctx},
}
client := &http.Client{Transport: transport}
svc, err := urlshortener.New(client)
if err != nil {
return "", err
}
resp, err := svc.Url.Insert(&urlshortener.Url{LongUrl: url}).Do()
if err != nil {
return "", err
}
return resp.Id, nil
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:20,代码来源:appidentity.go
示例20: upload
func upload(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: c},
},
}
ctx := cloud.NewContext(appengine.AppID(c), hc)
err := r.ParseMultipartForm(1048576)
if err != nil {
io.WriteString(w, err.Error())
return
}
file, fileHeader, err := r.FormFile("file")
if err != nil {
io.WriteString(w, err.Error())
return
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
io.WriteString(w, err.Error())
return
}
wc := storage.NewWriter(ctx, bucket, "slide/"+fileHeader.Filename)
wc.ContentType = http.DetectContentType(data)
if _, err := wc.Write(data); err != nil {
io.WriteString(w, err.Error())
return
}
if err := wc.Close(); err != nil {
io.WriteString(w, err.Error())
return
}
}
开发者ID:Tanoemon,项目名称:atelier-sou-vue,代码行数:42,代码来源:server.go
注:本文中的golang.org/x/oauth2/google.AppEngineTokenSource函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论