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

Golang internal.ProjID函数代码示例

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

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



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

示例1: Clusters

// Clusters returns a list of cluster resources from the specified zone.
// If no zone is specified, it returns all clusters under the user project.
func Clusters(ctx context.Context, zone string) ([]*Resource, error) {
	s := rawService(ctx)
	if zone == "" {
		resp, err := s.Projects.Clusters.List(internal.ProjID(ctx)).Do()
		if err != nil {
			return nil, err
		}
		return resourcesFromRaw(resp.Clusters), nil
	}
	resp, err := s.Projects.Zones.Clusters.List(internal.ProjID(ctx), zone).Do()
	if err != nil {
		return nil, err
	}
	return resourcesFromRaw(resp.Clusters), nil
}
开发者ID:rizzles,项目名称:convert,代码行数:17,代码来源:container.go


示例2: Operations

// Operations returns a list of operations from the specified zone.
// If no zone is specified, it looks up for all of the operations
// that are running under the user's project.
func Operations(ctx context.Context, zone string) ([]*Op, error) {
	s := rawService(ctx)
	if zone == "" {
		resp, err := s.Projects.Operations.List(internal.ProjID(ctx)).Do()
		if err != nil {
			return nil, err
		}
		return opsFromRaw(resp.Operations), nil
	}
	resp, err := s.Projects.Zones.Operations.List(internal.ProjID(ctx), zone).Do()
	if err != nil {
		return nil, err
	}
	return opsFromRaw(resp.Operations), nil
}
开发者ID:rizzles,项目名称:convert,代码行数:18,代码来源:container.go


示例3: call

func call(ctx context.Context, method string, req proto.Message, resp proto.Message) error {
	payload, err := proto.Marshal(req)
	if err != nil {
		return err
	}
	url := baseUrl(ctx) + internal.ProjID(ctx) + "/" + method
	r, err := internal.HTTPClient(ctx).Post(url, "application/x-protobuf", bytes.NewReader(payload))
	if err != nil {
		return err
	}
	defer r.Body.Close()
	all, err := ioutil.ReadAll(r.Body)
	if r.StatusCode != http.StatusOK {
		e := &errHTTP{
			StatusCode: r.StatusCode,
			err:        err,
		}
		if err == nil {
			e.Body = string(all)
		}
		return e
	}
	if err != nil {
		return err
	}
	if err = proto.Unmarshal(all, resp); err != nil {
		return err
	}
	return nil
}
开发者ID:rizzles,项目名称:convert,代码行数:30,代码来源:datastore.go


示例4: CreateSub

// CreateSub creates a Pub/Sub subscription on the backend.
// A subscription should subscribe to an existing topic.
//
// The messages that haven't acknowledged will be pushed back to the
// subscription again when the default acknowledgement deadline is
// reached. You can override the default deadline by providing a
// non-zero deadline. Deadline must not be specified to
// precision greater than one second.
//
// As new messages are being queued on the subscription, you
// may recieve push notifications regarding to the new arrivals.
// To receive notifications of new messages in the queue,
// specify an endpoint callback URL.
// If endpoint is an empty string the backend will not notify the
// client of new messages.
//
// If the subscription already exists an error will be returned.
func CreateSub(ctx context.Context, name string, topic string, deadline time.Duration, endpoint string) error {
	sub := &raw.Subscription{
		Topic: fullTopicName(internal.ProjID(ctx), topic),
	}
	if int64(deadline) > 0 {
		if !isSec(deadline) {
			return errors.New("pubsub: deadline must not be specified to precision greater than one second")
		}
		sub.AckDeadlineSeconds = int64(deadline / time.Second)
	}
	if endpoint != "" {
		sub.PushConfig = &raw.PushConfig{PushEndpoint: endpoint}
	}
	_, err := rawService(ctx).Projects.Subscriptions.Create(fullSubName(internal.ProjID(ctx), name), sub).Do()
	return err
}
开发者ID:herberteuler,项目名称:kythe,代码行数:33,代码来源:pubsub.go


示例5: Cluster

// Cluster returns metadata about the specified cluster.
func Cluster(ctx context.Context, zone, name string) (*Resource, error) {
	s := rawService(ctx)
	resp, err := s.Projects.Zones.Clusters.Get(internal.ProjID(ctx), zone, name).Do()
	if err != nil {
		return nil, err
	}
	return resourceFromRaw(resp), nil
}
开发者ID:rizzles,项目名称:convert,代码行数:9,代码来源:container.go


示例6: ModifyPushEndpoint

// ModifyPushEndpoint modifies the URL endpoint to modify the resource
// to handle push notifications coming from the Pub/Sub backend
// for the specified subscription.
func ModifyPushEndpoint(ctx context.Context, sub, endpoint string) error {
	_, err := rawService(ctx).Projects.Subscriptions.ModifyPushConfig(fullSubName(internal.ProjID(ctx), sub), &raw.ModifyPushConfigRequest{
		PushConfig: &raw.PushConfig{
			PushEndpoint: endpoint,
		},
	}).Do()
	return err
}
开发者ID:herberteuler,项目名称:kythe,代码行数:11,代码来源:pubsub.go


示例7: ModifyPushEndpoint

// ModifyPushEndpoint modifies the URL endpoint to modify the resource
// to handle push notifications coming from the Pub/Sub backend
// for the specified subscription.
func ModifyPushEndpoint(ctx context.Context, sub, endpoint string) error {
	return rawService(ctx).Subscriptions.ModifyPushConfig(&raw.ModifyPushConfigRequest{
		Subscription: fullSubName(internal.ProjID(ctx), sub),
		PushConfig: &raw.PushConfig{
			PushEndpoint: endpoint,
		},
	}).Do()
}
开发者ID:Jimmy99,项目名称:camlistore,代码行数:11,代码来源:pubsub.go


示例8: ModifyAckDeadline

// ModifyAckDeadline modifies the acknowledgement deadline
// for the messages retrieved from the specified subscription.
// Deadline must not be specified to precision greater than one second.
func ModifyAckDeadline(ctx context.Context, sub string, deadline time.Duration) error {
	if !isSec(deadline) {
		return errors.New("pubsub: deadline must not be specified to precision greater than one second")
	}
	return rawService(ctx).Subscriptions.ModifyAckDeadline(&raw.ModifyAckDeadlineRequest{
		Subscription:       fullSubName(internal.ProjID(ctx), sub),
		AckDeadlineSeconds: int64(deadline),
	}).Do()
}
开发者ID:Jimmy99,项目名称:camlistore,代码行数:12,代码来源:pubsub.go


示例9: ModifyAckDeadline

// ModifyAckDeadline modifies the acknowledgement deadline
// for the messages retrieved from the specified subscription.
// Deadline must not be specified to precision greater than one second.
//
// Deprecated: Use Subscription.Pull instead, which automatically extends ack deadlines.
func ModifyAckDeadline(ctx context.Context, sub string, id string, deadline time.Duration) error {
	if !isSec(deadline) {
		return errors.New("pubsub: deadline must not be specified to precision greater than one second")
	}
	_, err := rawService(ctx).Projects.Subscriptions.ModifyAckDeadline(fullSubName(internal.ProjID(ctx), sub), &raw.ModifyAckDeadlineRequest{
		AckDeadlineSeconds: int64(deadline / time.Second),
		AckIds:             []string{id},
	}).Do()
	return err
}
开发者ID:tav,项目名称:gcloud-golang,代码行数:15,代码来源:legacy.go


示例10: TopicExists

// TopicExists returns true if a topic exists with the specified name.
func TopicExists(ctx context.Context, name string) (bool, error) {
	_, err := rawService(ctx).Projects.Topics.Get(fullTopicName(internal.ProjID(ctx), name)).Do()
	if e, ok := err.(*googleapi.Error); ok && e.Code == http.StatusNotFound {
		return false, nil
	}
	if err != nil {
		return false, err
	}
	return true, nil
}
开发者ID:herberteuler,项目名称:kythe,代码行数:11,代码来源:pubsub.go


示例11: Ack

// Ack acknowledges one or more Pub/Sub messages on the
// specified subscription.
func Ack(ctx context.Context, sub string, id ...string) error {
	for idx, ackID := range id {
		if ackID == "" {
			return fmt.Errorf("pubsub: empty ackID detected at index %d", idx)
		}
	}
	_, err := rawService(ctx).Projects.Subscriptions.Acknowledge(fullSubName(internal.ProjID(ctx), sub), &raw.AcknowledgeRequest{
		AckIds: id,
	}).Do()
	return err
}
开发者ID:herberteuler,项目名称:kythe,代码行数:13,代码来源:pubsub.go


示例12: Operation

// Operation returns an operation.
func Operation(ctx context.Context, zone, name string) (*Op, error) {
	s := rawService(ctx)
	resp, err := s.Projects.Zones.Operations.Get(internal.ProjID(ctx), zone, name).Do()
	if err != nil {
		return nil, err
	}
	if resp.ErrorMessage != "" {
		return nil, errors.New(resp.ErrorMessage)
	}
	return opFromRaw(resp), nil
}
开发者ID:rizzles,项目名称:convert,代码行数:12,代码来源:container.go


示例13: pull

func pull(ctx context.Context, sub string, n int, retImmediately bool) ([]*Message, error) {
	if n < 1 || n > batchLimit {
		return nil, fmt.Errorf("pubsub: cannot pull less than one, more than %d messages, but %d was given", batchLimit, n)
	}
	resp, err := rawService(ctx).Projects.Subscriptions.Pull(fullSubName(internal.ProjID(ctx), sub), &raw.PullRequest{
		ReturnImmediately: retImmediately,
		MaxMessages:       int64(n),
	}).Do()
	if err != nil {
		return nil, err
	}
	msgs := make([]*Message, len(resp.ReceivedMessages))
	for i := 0; i < len(resp.ReceivedMessages); i++ {
		msg, err := toMessage(resp.ReceivedMessages[i])
		if err != nil {
			return nil, fmt.Errorf("pubsub: cannot decode the retrieved message at index: %d, PullResponse: %+v", i, resp.ReceivedMessages[i])
		}
		msgs[i] = msg
	}
	return msgs, nil
}
开发者ID:herberteuler,项目名称:kythe,代码行数:21,代码来源:pubsub.go


示例14: NewClient

// NewClient returns a new log client, logging to the named log.  The
// log must exist in the Google Cloud Platform project ID associated
// with the provided context. Use the google.golang.org/cloud package
// to create a context.
//
// The exported fields on the returned client may be modified before
// the client is used for logging. Once log entries are in flight,
// the fields must not be modified.
func NewClient(ctx context.Context, logName string) (*Client, error) {
	projID := internal.ProjID(ctx)
	httpClient := internal.HTTPClient(ctx)
	if projID == "" || httpClient == nil {
		return nil, errors.New("logging: invalid or non-google.golang.org/cloud Context")
	}
	svc, err := api.New(httpClient)
	if err != nil {
		return nil, err
	}
	c := &Client{
		svc:     svc,
		logs:    api.NewProjectsLogsEntriesService(svc),
		logName: logName,
		projID:  projID,
	}
	for i := range c.writer {
		level := Level(i)
		c.writer[level] = levelWriter{level, c}
		c.logger[level] = log.New(c.writer[level], "", 0)
	}
	return c, nil
}
开发者ID:Jimmy99,项目名称:camlistore,代码行数:31,代码来源:logging.go


示例15: Publish

// Publish publish messages to the topic's subscribers. It returns
// message IDs upon success.
func Publish(ctx context.Context, topic string, msgs ...*Message) ([]string, error) {
	var rawMsgs []*raw.PubsubMessage
	if len(msgs) == 0 {
		return nil, errors.New("pubsub: no messages to publish")
	}
	if len(msgs) > batchLimit {
		return nil, fmt.Errorf("pubsub: %d messages given, but maximum batch size is %d", len(msgs), batchLimit)
	}
	rawMsgs = make([]*raw.PubsubMessage, len(msgs))
	for i, msg := range msgs {
		rawMsgs[i] = &raw.PubsubMessage{
			Data:       base64.StdEncoding.EncodeToString(msg.Data),
			Attributes: msg.Attributes,
		}
	}
	resp, err := rawService(ctx).Projects.Topics.Publish(fullTopicName(internal.ProjID(ctx), topic), &raw.PublishRequest{
		Messages: rawMsgs,
	}).Do()
	if err != nil {
		return nil, err
	}
	return resp.MessageIds, nil
}
开发者ID:herberteuler,项目名称:kythe,代码行数:25,代码来源:pubsub.go


示例16: Publish

// Publish publish messages to the topic's subscribers. It returns
// message IDs upon success.
func Publish(ctx context.Context, topic string, msgs ...*Message) ([]string, error) {
	var rawMsgs []*raw.PubsubMessage
	if len(msgs) == 0 {
		return nil, errors.New("pubsub: no messages to publish")
	}
	if len(msgs) > batchLimit {
		return nil, fmt.Errorf("pubsub: %d messages given, but maximum batch size is %d", len(msgs), batchLimit)
	}
	rawMsgs = make([]*raw.PubsubMessage, len(msgs))
	for i, msg := range msgs {
		var rawLabels []*raw.Label
		if len(msg.Labels) > 0 {
			rawLabels = make([]*raw.Label, len(msg.Labels))
			j := 0
			for k, v := range msg.Labels {
				rawLabels[j] = &raw.Label{
					Key:      k,
					StrValue: v,
				}
				j++
			}
		}
		rawMsgs[i] = &raw.PubsubMessage{
			Data:  base64.URLEncoding.EncodeToString(msg.Data),
			Label: rawLabels,
		}
	}
	resp, err := rawService(ctx).Topics.PublishBatch(&raw.PublishBatchRequest{
		Topic:    fullTopicName(internal.ProjID(ctx), topic),
		Messages: rawMsgs,
	}).Do()
	if err != nil {
		return nil, err
	}
	return resp.MessageIds, nil
}
开发者ID:Jimmy99,项目名称:camlistore,代码行数:38,代码来源:pubsub.go


示例17: DeleteCluster

// DeleteCluster deletes a cluster.
func DeleteCluster(ctx context.Context, zone, name string) error {
	s := rawService(ctx)
	_, err := s.Projects.Zones.Clusters.Delete(internal.ProjID(ctx), zone, name).Do()
	return err
}
开发者ID:rizzles,项目名称:convert,代码行数:6,代码来源:container.go


示例18: Ack

// Ack acknowledges one or more Pub/Sub messages on the
// specified subscription.
func Ack(ctx context.Context, sub string, id ...string) error {
	return rawService(ctx).Subscriptions.Acknowledge(&raw.AcknowledgeRequest{
		Subscription: fullSubName(internal.ProjID(ctx), sub),
		AckId:        id,
	}).Do()
}
开发者ID:Jimmy99,项目名称:camlistore,代码行数:8,代码来源:pubsub.go


示例19: DeleteTopic

// DeleteTopic deletes the specified topic.
func DeleteTopic(ctx context.Context, name string) error {
	_, err := rawService(ctx).Projects.Topics.Delete(fullTopicName(internal.ProjID(ctx), name)).Do()
	return err
}
开发者ID:herberteuler,项目名称:kythe,代码行数:5,代码来源:pubsub.go


示例20: CreateTopic

// CreateTopic creates a new topic with the specified name on the backend.
// It will return an error if topic already exists.
func CreateTopic(ctx context.Context, name string) error {
	_, err := rawService(ctx).Topics.Create(&raw.Topic{
		Name: fullTopicName(internal.ProjID(ctx), name),
	}).Do()
	return err
}
开发者ID:Jimmy99,项目名称:camlistore,代码行数:8,代码来源:pubsub.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang opts.DialOpt类代码示例发布时间:2022-05-28
下一篇:
Golang datastore.Client类代码示例发布时间: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