本文整理匯總了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
}
示例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
}