mirror of
https://github.com/badkaktus/gorocket.git
synced 2025-07-15 01:14:21 +02:00
hookd response
This commit is contained in:
26
hooks.go
26
hooks.go
@ -21,18 +21,40 @@ type HookAttachment struct {
|
|||||||
Color string `json:"color"`
|
Color string `json:"color"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Hooks(msg *HookMessage, token string) {
|
type HookResponse struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Hooks(msg *HookMessage, token string) (*HookResponse, error) {
|
||||||
opt, _ := json.Marshal(msg)
|
opt, _ := json.Marshal(msg)
|
||||||
|
|
||||||
req, err := http.NewRequest("POST",
|
req, err := http.NewRequest("POST",
|
||||||
fmt.Sprintf("%s/hooks/%s", c.baseURL, token),
|
fmt.Sprintf("%s/hooks/%s", c.baseURL, token),
|
||||||
bytes.NewBuffer(opt))
|
bytes.NewBuffer(opt))
|
||||||
|
|
||||||
req.Header.Set("Accept", "application/json; charset=utf-8")
|
req.Header.Set("Accept", "application/json; charset=utf-8")
|
||||||
req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Request error")
|
log.Fatal("Request error")
|
||||||
//return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res, err := c.HTTPClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := HookResponse{}
|
||||||
|
|
||||||
|
if err = json.NewDecoder(res.Body).Decode(&resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user