1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/*
* Datadog API for Go
*
* Please see the included LICENSE file for licensing information.
*
* Copyright 2013 by authors and contributors.
*/
package datadog
import (
"fmt"
)
// Comment is a special form of event that appears in a stream.
type Comment struct {
Id *int `json:"id,omitempty"`
RelatedId *int `json:"related_event_id,omitempty"`
Handle *string `json:"handle,omitempty"`
Message *string `json:"message,omitempty"`
Resource *string `json:"resource,omitempty"`
Url *string `json:"url,omitempty"`
}
// reqComment is the container for receiving commenst.
type reqComment struct {
Comment *Comment `json:"comment,omitempty"`
}
// CreateComment adds a new comment to the system.
func (client *Client) CreateComment(handle, message string) (*Comment, error) {
var out reqComment
comment := Comment{Message: String(message)}
if len(handle) > 0 {
comment.Handle = String(handle)
}
if err := client.doJsonRequest("POST", "/v1/comments", &comment, &out); err != nil {
return nil, err
}
return out.Comment, nil
}
// CreateRelatedComment adds a new comment, but lets you specify the related
// identifier for the comment.
func (client *Client) CreateRelatedComment(handle, message string,
relid int) (*Comment, error) {
var out reqComment
comment := Comment{Message: String(message), RelatedId: Int(relid)}
if len(handle) > 0 {
comment.Handle = String(handle)
}
if err := client.doJsonRequest("POST", "/v1/comments", &comment, &out); err != nil {
return nil, err
}
return out.Comment, nil
}
// EditComment changes the message and possibly handle of a particular comment.
func (client *Client) EditComment(id int, handle, message string) error {
comment := Comment{Message: String(message)}
if len(handle) > 0 {
comment.Handle = String(handle)
}
return client.doJsonRequest("PUT", fmt.Sprintf("/v1/comments/%d", id),
&comment, nil)
}
// DeleteComment does exactly what you expect.
func (client *Client) DeleteComment(id int) error {
return client.doJsonRequest("DELETE", fmt.Sprintf("/v1/comments/%d", id),
nil, nil)
}
|