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

Golang v2.New函数代码示例

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

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



在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

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


示例2: connect

// connect - opens a new connection to bigquery,
// reusing the token if possible or regenerating a new auth token if required
func (c *Client) connect() (*bigquery.Service, error) {
	if c.token != nil {
		if !c.token.Valid() && c.service != nil {
			return c.service, nil
		}
	}

	// generate auth token and create service object
	//authScope := bigquery.BigqueryScope
	pemKeyBytes, err := ioutil.ReadFile(c.pemPath)
	if err != nil {
		panic(err)
	}

	t, err := google.JWTConfigFromJSON(
		pemKeyBytes,
		"https://www.googleapis.com/auth/bigquery")
	//t := jwt.NewToken(c.accountEmailAddress, bigquery.BigqueryScope, pemKeyBytes)
	client := t.Client(oauth2.NoContext)

	service, err := bigquery.New(client)
	if err != nil {
		return nil, err
	}

	c.service = service
	return service, nil
}
开发者ID:ferryzhou,项目名称:bqexport,代码行数:30,代码来源:show.go


示例3: newBigqueryService

func newBigqueryService(client *http.Client) (*bigqueryService, error) {
	s, err := bq.New(client)
	if err != nil {
		return nil, fmt.Errorf("constructing bigquery client: %v", err)
	}

	return &bigqueryService{s: s}, nil
}
开发者ID:vichetuc,项目名称:gcloud-golang,代码行数:8,代码来源:service.go


示例4: newBigqueryService

func newBigqueryService(client *http.Client, endpoint string) (*bigqueryService, error) {
	s, err := bq.New(client)
	if err != nil {
		return nil, fmt.Errorf("constructing bigquery client: %v", err)
	}
	s.BasePath = endpoint

	return &bigqueryService{s: s}, nil
}
开发者ID:trythings,项目名称:trythings,代码行数:9,代码来源:service.go


示例5: NewBigQueryService

// NewBigQueryService returns a new BigQuery service (client), authenticated via OAuth2/JWT.
//
// NOTE: This function authenticates with Google OAuth2 service,
// thus susceptible to network delays and blocks.
func NewBigQueryService(c *jwt.Config) (service *bigquery.Service, err error) {
	// Create *http.Client.
	client := c.Client(oauth2.NoContext)

	// Create authenticated BigQuery service.
	service, err = bigquery.New(client)

	// No need to check if err != nil since we return anyways.
	return
}
开发者ID:guregu,项目名称:go-bqstreamer,代码行数:14,代码来源:bqstreamer.go


示例6: connect

// Helper method to create an authenticated connection.
func connect() (*oauth2.Token, *bigquery.Service, error) {
	if *clientId == "" {
		return nil, nil, fmt.Errorf("no client id specified")
	}
	if *serviceAccount == "" {
		return nil, nil, fmt.Errorf("no service account specified")
	}
	if *projectId == "" {
		return nil, nil, fmt.Errorf("no project id specified")
	}
	authScope := bigquery.BigqueryScope
	if *pemFile == "" {
		return nil, nil, fmt.Errorf("no credentials specified")
	}
	pemBytes, err := ioutil.ReadFile(*pemFile)
	if err != nil {
		return nil, nil, fmt.Errorf("could not access credential file %v - %v", pemFile, err)
	}

	jwtConfig := &jwt.Config{
		Email:      *serviceAccount,
		Scopes:     []string{authScope},
		PrivateKey: pemBytes,
		TokenURL:   "https://accounts.google.com/o/oauth2/token",
	}
	token, err := jwtConfig.TokenSource(oauth2.NoContext).Token()
	if err != nil {
		return nil, nil, err
	}
	if !token.Valid() {
		return nil, nil, fmt.Errorf("invalid token for BigQuery oauth")
	}

	config := &oauth2.Config{
		ClientID:     *clientId,
		ClientSecret: *clientSecret,
		Scopes:       []string{authScope},
		Endpoint: oauth2.Endpoint{
			AuthURL:  "https://accounts.google.com/o/oauth2/auth",
			TokenURL: "https://accounts.google.com/o/oauth2/token",
		},
	}
	client := config.Client(oauth2.NoContext, token)

	service, err := bigquery.New(client)
	if err != nil {
		fmt.Printf("Failed to create new service: %v\n", err)
		return nil, nil, err
	}

	return token, service, nil
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:53,代码来源:client.go


示例7: BuildBigQueryTables

// BuildBigQueryTables is a utility to configure BigQuery table for logging.
func BuildBigQueryTables(req *wcg.Request) error {
	if !LogSinkConfig.IsBigQueryEnabled() {
		return fmt.Errorf("BigQuery is not enabled, please check bigquery_project and bigquery_dataset configuration.")
	}

	client, err := bq.NewHTTPClient(NewContext(req))
	if err != nil {
		return err
	}
	service, err := bigquery.New(client)
	if err != nil {
		return err
	}
	projectID := LogSinkConfig.BigqueryProject
	datasetID := LogSinkConfig.BigqueryDataset
	for tableID, tbl := range LogSinkConfig.schema {
		tbl.TableReference.ProjectId = projectID
		tbl.TableReference.DatasetId = datasetID

		tbl1, err := service.Tables.Get(projectID, datasetID, tableID).Do()
		if err == nil {
			req.Logger.Debugf("Table %q already exists on \"%s/%s\"", tableID, projectID, datasetID)
			if len(tbl.Schema.Fields) < len(tbl1.Schema.Fields) {
				req.Logger.Fatalf("You cannot remove fields from table %q!!", tableID)
				continue
			}
			if len(tbl.Schema.Fields) == len(tbl1.Schema.Fields) {
				req.Logger.Infof("No filed changes on %q", tableID)
				continue
			}
			req.Logger.Infof("Trying to patch the exising table %q in %s/%s", tableID, LogSinkConfig.BigqueryProject, LogSinkConfig.BigqueryDataset)
			upd := service.Tables.Patch(LogSinkConfig.BigqueryProject, LogSinkConfig.BigqueryDataset, tableID, tbl)
			_, err = upd.Do()
			if err != nil {
				req.Logger.Errorf("Could not patch %q in %s/%s: %v", tableID, LogSinkConfig.BigqueryProject, LogSinkConfig.BigqueryDataset, err)
				continue
			}
			req.Logger.Infof("Table %q has been successfully updated in %s/%s", tableID, LogSinkConfig.BigqueryProject, LogSinkConfig.BigqueryDataset)
		} else {
			req.Logger.Infof("Trying to create a new table %q in %s/%s", tableID, LogSinkConfig.BigqueryProject, LogSinkConfig.BigqueryDataset)
			ins := service.Tables.Insert(LogSinkConfig.BigqueryProject, LogSinkConfig.BigqueryDataset, tbl)
			_, err = ins.Do()
			if err != nil {
				req.Logger.Errorf("Could not create a new table %q in %s/%s: %v", tableID, LogSinkConfig.BigqueryProject, LogSinkConfig.BigqueryDataset, err)
				continue
			}
			req.Logger.Infof("Table %q has been successfully created in %s/%s", tableID, LogSinkConfig.BigqueryProject, LogSinkConfig.BigqueryDataset)
		}
	}
	return nil
}
开发者ID:speedland,项目名称:service,代码行数:52,代码来源:logger.go


示例8: NewLogSinkWithContext

// NewLogSinkWithContext creates a new *LogSink for GAE
func NewLogSinkWithContext(format string, ctx context.Context) *LogSink {
	var _bq *bigquery.Service
	if LogSinkConfig.IsBigQueryEnabled() {
		client, err := bq.NewHTTPClient(ctx)
		if err == nil {
			_bq, _ = bigquery.New(client)
		}
	}
	return &LogSink{
		formatter: wcg.NewLogRecordFormatter(format),
		ctx:       ctx,
		bigquery:  _bq,
	}
}
开发者ID:speedland,项目名称:service,代码行数:15,代码来源:logger.go


示例9: NewGAELogSinkWithContext

func NewGAELogSinkWithContext(format string, ctx appengine.Context) *GAELogSink {
	var bq *bigquery.Service
	if LogSinkConfig.IsBigQueryEnabled() {
		client, err := serviceaccount.NewClient(ctx, bigquery.BigqueryScope)
		if err == nil {
			bq, _ = bigquery.New(client)
		}
	}
	return &GAELogSink{
		formatter: NewLogRecordFormatter(format),
		ctx:       ctx,
		bigquery:  bq,
	}
}
开发者ID:speedland,项目名称:wcg,代码行数:14,代码来源:logger.go


示例10: deleteDataset

func deleteDataset(t *testing.T, ctx context.Context, datasetID string) {
	tc := testutil.SystemTest(t)
	hc, err := google.DefaultClient(ctx, rawbq.CloudPlatformScope)
	if err != nil {
		t.Errorf("DefaultClient: %v", err)
	}
	s, err := rawbq.New(hc)
	if err != nil {
		t.Errorf("bigquery.New: %v", err)
	}
	call := s.Datasets.Delete(tc.ProjectID, datasetID)
	call.DeleteContents(true)
	call.Context(ctx)
	if err := call.Do(); err != nil {
		t.Errorf("deleteDataset(%q): %v", datasetID, err)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:17,代码来源:snippet_test.go


示例11: NewClient

// NewClient ...
func NewClient(email, pemKeyPath string) (*Client, error) {
	pemKeyBytes, err := ioutil.ReadFile(pemKeyPath)
	if err != nil {
		return nil, err
	}
	conf := jwt.Config{
		Email:      email,
		PrivateKey: pemKeyBytes,
		Scopes:     []string{bigquery.BigqueryScope},
		TokenURL:   google.JWTTokenURL,
	}
	client := conf.Client(oauth2.NoContext)
	service, err := bigquery.New(client)
	if err != nil {
		return nil, err
	}
	return &Client{BigQueryService: service}, nil
}
开发者ID:gotokatsuya,项目名称:bigquery,代码行数:19,代码来源:client.go


示例12: Connect

func (w *Writer) Connect(email string, pem []byte) error {
	cfg := jwt.Config{
		Email:      email,
		PrivateKey: pem,
		Scopes:     []string{bq.BigqueryScope},
		TokenURL:   "https://accounts.google.com/o/oauth2/token",
	}
	ctx := context.Background()
	client := cfg.Client(ctx)
	bq, err := bq.New(client)
	if err != nil {
		w.warnf("connect error %v", err)
		return err
	}
	w.service = &bigqueryService{bq}
	w.debugf("connected")
	return nil
}
开发者ID:najeira,项目名称:bigquery,代码行数:18,代码来源:writer.go


示例13: NewService

func NewService(req *wcg.Request) (*bigquery.Service, error) {
	var ctx appengine.Context
	tmp := req.Local("__gaetest__context")
	if tmp != nil {
		ctx = tmp.(appengine.Context)
	} else {
		ctx = appengine.NewContext(req.HttpRequest())
	}

	client, err := serviceaccount.NewClient(ctx, bigquery.BigqueryScope)
	if err != nil {
		return nil, err
	}
	svc, err := bigquery.New(client)
	if err != nil {
		return nil, err
	}
	return svc, nil
}
开发者ID:speedland,项目名称:wcg,代码行数:19,代码来源:helper.go


示例14: NewService

// NewService returns a new bigquery service accessor instance
func NewService(req *wcg.Request) (*bigquery.Service, error) {
	var ctx context.Context
	tmp := req.Local("__gaetest__context")
	if tmp != nil {
		ctx = tmp.(context.Context)
	} else {
		ctx = appengine.NewContext(req.HTTPRequest())
	}

	client, err := NewHTTPClient(ctx)
	if err != nil {
		return nil, err
	}
	svc, err := bigquery.New(client)
	if err != nil {
		return nil, err
	}
	return svc, nil
}
开发者ID:speedland,项目名称:service,代码行数:20,代码来源:helper.go


示例15: newBQDataset

func newBQDataset(client *http.Client, dsProj string, dsId string) (*bqDataset,
	error) {

	service, err := bigquery.New(client)
	if err != nil {
		log.Fatalf("Unable to create BigQuery service: %v", err)
	}

	return &bqDataset{
		project: dsProj,
		id:      dsId,
		bq:      service,
		dataset: &bigquery.Dataset{
			DatasetReference: &bigquery.DatasetReference{
				DatasetId: dsId,
				ProjectId: dsProj,
			},
		},
		jobsets: make(map[string]*list.List),
	}, nil
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:21,代码来源:bigquery.go


示例16: newBQDataset

func newBQDataset(client *http.Client, dsProj string, dsId string) (*bqDataset,
	error) {

	service, err := bigquery.New(client)
	if err != nil {
		return nil, err
	}

	return &bqDataset{
		project: dsProj,
		id:      dsId,
		bq:      service,
		dataset: &bigquery.Dataset{
			DatasetReference: &bigquery.DatasetReference{
				DatasetId: dsId,
				ProjectId: dsProj,
			},
		},
		jobsets: make(map[string]*list.List),
	}, nil
}
开发者ID:GamerockSA,项目名称:dex,代码行数:21,代码来源:bigquery.go


示例17: handlerInsert

func handlerInsert(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,
	}

	jsonValue, err := ironmole.BuildJsonValue(&c)
	if err != nil {
		log.Errorf(ctx, "%v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	res, err := ironmole.Insert(bq, "cp300demo1", "go2bq", "Container2", jsonValue)
	if err != nil {
		log.Errorf(ctx, "%v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	for _, insertError := range res.InsertErrors {
		for _, err := range insertError.Errors {
			log.Errorf(ctx, "Insert Error = %v", err)
		}
	}
}
开发者ID:sinmetal,项目名称:ironmole,代码行数:40,代码来源:example.go


示例18: handlerTableMoge

func handlerTableMoge(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 {
		log.Errorf(ctx, "%v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	table := "Moge"
	tableParam := r.FormValue("table")
	if len(tableParam) > 0 {
		table = tableParam
	}

	moge := Moge{}
	schema, err := ironmole.BuildTableSchemaWithContext(ctx, &moge)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	err = ironmole.CreateTable(bq, "cp300demo1", "go2bq", table, schema)
	if err != nil {
		log.Errorf(ctx, "%v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write([]byte("done"))
}
开发者ID:sinmetal,项目名称:ironmole,代码行数:40,代码来源:example.go


示例19: initBigQueryService

func initBigQueryService(credentialsFileName string) error {
	var client *http.Client

	credentialsData, err := ioutil.ReadFile(credentialsFileName)
	if err != nil {
		return err
	}

	var conf *jwt.Config
	conf, err = google.JWTConfigFromJSON(credentialsData, bigQueryScope)
	if err != nil {
		return err
	}

	client = conf.Client(oauth2.NoContext)

	if bq, err = bigquery.New(client); err != nil {
		return err
	}

	return nil
}
开发者ID:erans,项目名称:nsq-to-bigquery,代码行数:22,代码来源:nsq_to_bigquery.go


示例20: createTables

func createTables(writer http.ResponseWriter, req *http.Request) {
	context := appengine.NewContext(req)
	client, err := google.DefaultClient(context, scope)
	if err != nil {
		writer.WriteHeader(http.StatusInternalServerError)
		log.Criticalf(context, "Unable to get default client: %v", err)
		return
	}

	service, err := bigquery.New(client)
	if err != nil {
		log.Criticalf(context, "tables/tables.go: Unable to create bigquery service: %v", err)
		writer.WriteHeader(http.StatusUnauthorized)
		return
	}

	t := time.Now()
	for i := 1; i < 3; i++ {
		t = t.AddDate(0, 0, 1)
		log.Infof(context, "tables/tables.go: Creating tables for %v-%v-%v", t.Year(), int(t.Month()), t.Day())
		insertTablesForTime(t, service, errorHandler(writer, context))
	}
}
开发者ID:tejohnso,项目名称:go-bq-table-insert,代码行数:23,代码来源:tables.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang v2.Job类代码示例发布时间:2022-05-28
下一篇:
Golang appengine.NewContext函数代码示例发布时间: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