當前位置: 首頁>>代碼示例>>Golang>>正文


Golang structs.EventFireRequest類代碼示例

本文整理匯總了Golang中github.com/hashicorp/consul/consul/structs.EventFireRequest的典型用法代碼示例。如果您正苦於以下問題:Golang EventFireRequest類的具體用法?Golang EventFireRequest怎麽用?Golang EventFireRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了EventFireRequest類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestInternal_EventFire_Token

func TestInternal_EventFire_Token(t *testing.T) {
	dir, srv := testServerWithConfig(t, func(c *Config) {
		c.ACLDatacenter = "dc1"
		c.ACLMasterToken = "root"
		c.ACLDownPolicy = "deny"
		c.ACLDefaultPolicy = "deny"
	})
	defer os.RemoveAll(dir)
	defer srv.Shutdown()

	codec := rpcClient(t, srv)
	defer codec.Close()

	testutil.WaitForLeader(t, srv.RPC, "dc1")

	// No token is rejected
	event := structs.EventFireRequest{
		Name:       "foo",
		Datacenter: "dc1",
		Payload:    []byte("nope"),
	}
	err := msgpackrpc.CallWithCodec(codec, "Internal.EventFire", &event, nil)
	if err == nil || err.Error() != permissionDenied {
		t.Fatalf("bad: %s", err)
	}

	// Root token is allowed to fire
	event.Token = "root"
	err = msgpackrpc.CallWithCodec(codec, "Internal.EventFire", &event, nil)
	if err != nil {
		t.Fatalf("err: %s", err)
	}
}
開發者ID:rchicoli,項目名稱:consul,代碼行數:33,代碼來源:internal_endpoint_test.go

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

示例3: 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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。