代码拉取完成,页面将自动刷新
package client
import (
"encoding/json"
corev2 "github.com/sensu/sensu-go/api/core/v2"
"github.com/sensu/sensu-go/types"
)
var hooksPath = createNSBasePath(coreAPIGroup, coreAPIVersion, "hooks")
// CreateHook creates new hook on configured Sensu instance
func (client *RestClient) CreateHook(hook *types.HookConfig) (err error) {
bytes, err := json.Marshal(hook)
if err != nil {
return err
}
path := hooksPath(hook.Namespace)
res, err := client.R().SetBody(bytes).Post(path)
if err != nil {
return err
}
if res.StatusCode() >= 400 {
return UnmarshalError(res)
}
return nil
}
// UpdateHook updates given hook on configured Sensu instance
func (client *RestClient) UpdateHook(hook *types.HookConfig) (err error) {
bytes, err := json.Marshal(hook)
if err != nil {
return err
}
path := hooksPath(hook.Namespace, hook.Name)
res, err := client.R().SetBody(bytes).Put(path)
if err != nil {
return err
}
if res.StatusCode() >= 400 {
return UnmarshalError(res)
}
return nil
}
// DeleteHook deletes hook from configured Sensu instance
func (client *RestClient) DeleteHook(namespace, name string) error {
return client.Delete(hooksPath(namespace, name))
}
// FetchHook fetches a specific hook
func (client *RestClient) FetchHook(name string) (*types.HookConfig, error) {
var hook *types.HookConfig
path := hooksPath(client.config.Namespace(), name)
res, err := client.R().Get(path)
if err != nil {
return nil, err
}
if res.StatusCode() >= 400 {
return nil, UnmarshalError(res)
}
err = json.Unmarshal(res.Body(), &hook)
return hook, err
}
// ListHooks fetches all hooks from configured Sensu instance
func (client *RestClient) ListHooks(namespace string, options *ListOptions) ([]corev2.HookConfig, error) {
var hooks []corev2.HookConfig
if err := client.List(hooksPath(namespace), &hooks, options); err != nil {
return hooks, err
}
return hooks, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。