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


Golang Network.SendRequest方法代碼示例

本文整理匯總了Golang中github.com/apache/brooklyn-client/cli/net.Network.SendRequest方法的典型用法代碼示例。如果您正苦於以下問題:Golang Network.SendRequest方法的具體用法?Golang Network.SendRequest怎麽用?Golang Network.SendRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/apache/brooklyn-client/cli/net.Network的用法示例。


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

示例1: AddPolicy

// WIP
func AddPolicy(network *net.Network, application, entity, policy string, config map[string]string) (models.PolicySummary, error) {
	path := fmt.Sprintf("/v1/applications/%s/entities/%s/policies", application, entity)
	data := url.Values{}
	data.Set("policyType", policy)
	//data.Add("config", config)
	req := network.NewPostRequest(path, bytes.NewBufferString(data.Encode()))
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
	var policySummary models.PolicySummary
	body, err := network.SendRequest(req)
	if err != nil {
		return policySummary, err
	}
	err = json.Unmarshal(body, &policySummary)
	return policySummary, err
}
開發者ID:m4rkmckenna,項目名稱:brooklyn-client,代碼行數:17,代碼來源:policies.go

示例2: TriggerEffector

func TriggerEffector(network *net.Network, application, entity, effector string, params []string, args []string) (string, error) {
	if len(params) != len(args) {
		return "", errors.New(strings.Join([]string{"Parameters not supplied:", strings.Join(params, ", ")}, " "))
	}
	path := fmt.Sprintf("/v1/applications/%s/entities/%s/effectors/%s", application, entity, effector)
	data := url.Values{}
	for i := range params {
		data.Set(params[i], args[i])
	}
	req := network.NewPostRequest(path, bytes.NewBufferString(data.Encode()))
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	req.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))
	body, err := network.SendRequest(req)
	if err != nil {
		return "", err
	}
	return string(body), nil
}
開發者ID:m4rkmckenna,項目名稱:brooklyn-client,代碼行數:18,代碼來源:effectors.go


注:本文中的github.com/apache/brooklyn-client/cli/net.Network.SendRequest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。