• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang appengine.AppID函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中google/golang.org/appengine.AppID函数的典型用法代码示例。如果您正苦于以下问题:Golang AppID函数的具体用法?Golang AppID怎么用?Golang AppID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了AppID函数的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: 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


示例3: file

func file(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	fname := r.URL.Query().Get("f")
	n := r.URL.Query().Get("n")
	lineno, _ := strconv.Atoi(n)

	f, err := ioutil.ReadFile(fname)
	if err != nil {
		serveError(w, err)
		return
	}

	fp := make(map[int]string)
	for k, v := range strings.Split(string(f), "\n") {
		fp[k+1] = v
	}

	v := struct {
		Env      map[string]string
		Filename string
		Lineno   int
		Fp       map[int]string
	}{
		Env: map[string]string{
			"APPLICATION_ID": appengine.AppID(ctx),
		},
		Filename: fname,
		Lineno:   lineno,
		Fp:       fp,
	}

	_ = templates.ExecuteTemplate(w, "file", v)
}
开发者ID:flowlo,项目名称:appstats,代码行数:32,代码来源:handler.go


示例4: getCloudContext

func getCloudContext(aeCtx context.Context) (context.Context, error) {
	data, err := ioutil.ReadFile("gcs.xxjson")
	if err != nil {
		return nil, err
	}

	conf, err := google.JWTConfigFromJSON(
		data,
		storage.ScopeFullControl,
	)
	if err != nil {
		return nil, err
	}

	tokenSource := conf.TokenSource(aeCtx)

	hc := &http.Client{
		Transport: &oauth2.Transport{
			Source: tokenSource,
			Base:   &urlfetch.Transport{Context: aeCtx},
		},
	}

	return cloud.NewContext(appengine.AppID(aeCtx), hc), nil
}
开发者ID:rjrobinson,项目名称:GolangTraining,代码行数:25,代码来源:storage.go


示例5: 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.
	hc, err := google.DefaultClient(ctx, bigquery.BigqueryScope)
	if err != nil {
		return nil, fmt.Errorf("could not create http client: %v", err)
	}

	// Create the BigQuery service.
	bq, err := bigquery.New(hc)
	if err != nil {
		return nil, fmt.Errorf("could not create service: %v", err)
	}

	// Get the current application ID, which is the same as the project ID.
	projectID := appengine.AppID(ctx)

	// Return a list of IDs.
	var ids []string
	datasets, err := bq.Datasets.List(projectID).Do()
	if err != nil {
		return nil, fmt.Errorf("could not list datasets for %q: %v", projectID, err)
	}
	for _, d := range datasets.Datasets {
		ids = append(ids, d.Id)
	}
	return ids, nil
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:29,代码来源:app.go


示例6: clone

// Clone creates a local copy of the repository accessible at
// github.com/user/repo with token, in a system temp directory.
func clone(c context.Context, repoOwner, repoName, userName, token string) (repository.Repo, error) {
	dir, err := ioutil.TempDir("", fmt.Sprintf("%s-%s", userName, repoName))
	if err != nil {
		return nil, err
	}
	cloneCmd := exec.Command("git", "clone", makeRemoteURL(userName, token, repoOwner, repoName), dir)
	if _, err := cloneCmd.CombinedOutput(); err != nil {
		return nil, err
	}
	repo, err := repository.NewGitRepo(dir)
	if err != nil {
		return nil, err
	}
	if err := repo.PullNotes(remoteName, notesRefPattern); err != nil {
		return nil, err
	}
	fetchCmd := exec.Command("git", "fetch", "origin", fetchSpec)
	fetchCmd.Dir = dir
	if _, err := fetchCmd.CombinedOutput(); err != nil {
		return nil, err
	}
	configUserCmd := exec.Command("git", "config", "--local", "--add", "user.name", "Github Mirror")
	configUserCmd.Dir = dir
	if _, err := configUserCmd.CombinedOutput(); err != nil {
		return nil, err
	}
	userEmail := appengine.AppID(c) + "@appspot.gserviceaccount.com"
	configEmailCmd := exec.Command("git", "config", "--local", "--add", "user.email", userEmail)
	configEmailCmd.Dir = dir
	if _, err := configEmailCmd.CombinedOutput(); err != nil {
		return nil, err
	}
	return repo, nil
}
开发者ID:google,项目名称:git-pull-request-mirror,代码行数:36,代码来源:ephemeral.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: 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


示例9: view

func view(w http.ResponseWriter, r *http.Request, m map[string]interface{}) {

	cntr := 1

	tplAdder, tplExec := tplx.FuncTplBuilder(w, r)
	tplAdder("n_html_title", "Application, Module and Instance Info", nil)
	tplAdder("n_cont_1", "<pre>{{.}}</pre>", instance_mgt.GetStatic().String())
	tplAdder("n_cont_2", "<p>{{.}} views</p>", cntr)
	tplAdder("n_cont_0", `
		<p>AppID is `+appengine.AppID(appengine.NewContext(r))+`</p>
		<p>On the development server, call 
		<a href='/instance-info/collect' 
		target='collect' >collect</a> first.</p>

		<p><a href='/instance-info/`+instance_mgt.GetStatic().InstanceID+`'>specific url</a></p>
		
		`, "")

	tplExec(w, r)

	/*
	 Requests are routed randomly accross instances

	 Following is just a futile try to register
	 an instance specific handler.
	 It is only useful, when we request an instance
	 specifically via specific hostname
	*/
	SuppressPanicUponDoubleRegistration(
		w, r, "/instance-info/"+instance_mgt.GetStatic().InstanceID, loghttp.Adapter(view))

}
开发者ID:aarzilli,项目名称:tools,代码行数:32,代码来源:view.go


示例10: 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


示例11: DeleteMetric

func DeleteMetric(c context.Context, metric string) (err error) {
	service, err := NewMonitoringService(c)
	if err != nil {
		return
	}
	_, err = service.MetricDescriptors.Delete(appengine.AppID(c), metric).Do()
	return
}
开发者ID:pombredanne,项目名称:appengine-toolkit,代码行数:8,代码来源:monitoring.go


示例12: fullSubscription

func fullSubscription(c context.Context, s string) string {
	re, _ := regexp.Compile(`projects/([\w-]+)/subscriptions/([\w-]+)`)
	if re.MatchString(s) {
		return s
	} else {
		return fmt.Sprintf("projects/%s/subscriptions/%s", appengine.AppID(c), s)
	}
}
开发者ID:pombredanne,项目名称:appengine-toolkit,代码行数:8,代码来源:pubsub.go


示例13: DatastoreInfo

func (session *Session) DatastoreInfo() (err error) {
	c, err := session.Context()
	if err != nil {
		return
	}
	log.Printf("App ID %q", appengine.AppID(c))
	return
}
开发者ID:timburks,项目名称:remote,代码行数:8,代码来源:remote.go


示例14: 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


示例15: 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


示例16: auth

func auth(r *http.Request) (context.Context, error) {
	c := appengine.NewContext(r)
	client, err := google.DefaultClient(c, storage.ScopeFullControl)
	if err != nil {
		return nil, err
	}

	ctx := cloud.NewContext(appengine.AppID(c), client)

	return ctx, nil
}
开发者ID:reedperry,项目名称:gogram,代码行数:11,代码来源:gcs.go


示例17: alertAdmins

func alertAdmins(c context.Context, key *datastore.Key, entity Lockable, reason string) error {
	sender := "[email protected]" + appengine.AppID(c) + ".appspot.com"

	msg := &mail.Message{
		Sender:  sender,
		Subject: reason,
		Body:    fmt.Sprintf("key: %s, entity: %#v", key.String(), entity),
	}

	return mail.SendToAdmins(c, msg)
}
开发者ID:CaptainCodeman,项目名称:datastore-locker,代码行数:11,代码来源:email.go


示例18: 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


示例19: httpClient

func httpClient(r *http.Request) *http.Client {
	c := appengine.NewContext(r)
	return &http.Client{
		Transport: &httputil.Transport{
			Token:        github.Token,
			ClientID:     github.ClientID,
			ClientSecret: github.ClientSecret,
			Base:         &urlfetch.Transport{Context: c, Deadline: 10 * time.Second},
			UserAgent:    fmt.Sprintf("%s (+http://%s/-/bot)", appengine.AppID(c), r.Host),
		},
	}
}
开发者ID:golang,项目名称:gddo,代码行数:12,代码来源:main.go


示例20: 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)

	bucketName, err := file.DefaultBucketName(c)
	if err != nil {
		c.Errorf("failed to get default GCS bucket name: %v", err)
		return
	}

	config := google.NewAppEngineConfig(c, storage.ScopeFullControl)
	ctx := cloud.NewContext(appengine.AppID(c), &http.Client{Transport: config.NewTransport()})

	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", bucketName)

	d := &demo{
		c:      c,
		w:      w,
		ctx:    ctx,
		bucket: bucketName,
	}

	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:qwo,项目名称:abelana-gcp,代码行数:53,代码来源:app.go



注:本文中的google/golang.org/appengine.AppID函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang appengine.BlobKey函数代码示例发布时间:2022-05-28
下一篇:
Golang transport.DialGRPC函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap