当前位置: 首页>>代码示例>>Golang>>正文


Golang EventFireRequest.AllowStale方法代码示例

本文整理汇总了Golang中github.com/hashicorp/consul/consul/structs.EventFireRequest.AllowStale方法的典型用法代码示例。如果您正苦于以下问题:Golang EventFireRequest.AllowStale方法的具体用法?Golang EventFireRequest.AllowStale怎么用?Golang EventFireRequest.AllowStale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/hashicorp/consul/consul/structs.EventFireRequest的用法示例。


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

示例1: UserEvent

// UserEvent is used to fire an event via the Serf layer on the LAN
func (a *Agent) UserEvent(dc, token string, params *UserEvent) error {
	// Validate the params
	if err := validateUserEventParams(params); err != nil {
		return err
	}

	// Format message
	var err error
	if params.ID, err = uuid.GenerateUUID(); err != nil {
		return fmt.Errorf("UUID generation failed: %v", err)
	}
	params.Version = userEventMaxVersion
	payload, err := encodeMsgPack(&params)
	if err != nil {
		return fmt.Errorf("UserEvent encoding failed: %v", err)
	}

	// Service the event fire over RPC. This ensures that we authorize
	// the request against the token first.
	args := structs.EventFireRequest{
		Datacenter:   dc,
		Name:         params.Name,
		Payload:      payload,
		QueryOptions: structs.QueryOptions{Token: token},
	}

	// Any server can process in the remote DC, since the
	// gossip will take over anyways
	args.AllowStale = true
	var out structs.EventFireResponse
	return a.RPC("Internal.EventFire", &args, &out)
}
开发者ID:rchicoli,项目名称:consul,代码行数:33,代码来源:user_event.go

示例2: UserEvent

// UserEvent is used to fire an event via the Serf layer on the LAN
func (a *Agent) UserEvent(dc string, params *UserEvent) error {
	// Validate the params
	if err := validateUserEventParams(params); err != nil {
		return err
	}

	// Format message
	params.ID = generateUUID()
	params.Version = userEventMaxVersion
	payload, err := encodeUserEvent(&params)
	if err != nil {
		return fmt.Errorf("UserEvent encoding failed: %v", err)
	}

	// Check if this is the local DC, fire locally
	if dc == "" || dc == a.config.Datacenter {
		if a.server != nil {
			return a.server.UserEvent(params.Name, payload)
		} else {
			return a.client.UserEvent(params.Name, payload)
		}
	} else {
		// Send an RPC to remote datacenter to service this
		args := structs.EventFireRequest{
			Datacenter: dc,
			Name:       params.Name,
			Payload:    payload,
		}

		// Any server can process in the remote DC, since the
		// gossip will take over anyways
		args.AllowStale = true
		var out structs.EventFireResponse
		return a.RPC("Internal.EventFire", &args, &out)
	}
}
开发者ID:hungld,项目名称:consul,代码行数:37,代码来源:user_event.go


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