-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathboard.go
124 lines (102 loc) · 3.63 KB
/
board.go
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package honeycombio
import (
"context"
"fmt"
)
// Boards describes all the board-related methods that the Honeycomb API
// supports.
//
// API docs: https://docs.honeycomb.io/api/boards-api/
type Boards interface {
// List all boards.
List(ctx context.Context) ([]Board, error)
// Get a board by its ID. Returns ErrNotFound if there is no board with the
// given ID.
Get(ctx context.Context, id string) (*Board, error)
// Create a new board. When creating a new board ID may not be set.
Create(ctx context.Context, b *Board) (*Board, error)
// Update an existing board.
Update(ctx context.Context, b *Board) (*Board, error)
// Delete a board.
Delete(ctx context.Context, id string) error
}
// boards implements Boards.
type boards struct {
client *Client
}
// Compile-time proof of interface implementation by type boards.
var _ Boards = (*boards)(nil)
// Board represents a Honeycomb board.
//
// API docs: https://docs.honeycomb.io/api/boards-api/#fields-on-a-board
type Board struct {
ID string `json:"id,omitempty"`
// Name of the board, this is displayed in the Honeycomb UI. This field is
// required.
Name string `json:"name"`
// Description of the board.
Description string `json:"description,omitempty"`
// How the board should be displayed in the UI, defaults to "list".
Style BoardStyle `json:"style,omitempty"`
// A list of queries displayed on the board, in order of appearance.
Queries []BoardQuery `json:"queries"`
}
// BoardStyle determines how a Board should be displayed within the Honeycomb UI.
type BoardStyle string
// Declaration of board styles.
const (
BoardStyleList BoardStyle = "list"
BoardStyleVisual BoardStyle = "visual"
)
// BoardStyles returns an exhaustive list of board styles.
func BoardStyles() []BoardStyle {
return []BoardStyle{BoardStyleList, BoardStyleVisual}
}
// BoardQuery represents a query that is part of a board.
type BoardQuery struct {
Caption string `json:"caption,omitempty"`
// Defaults to graph.
QueryStyle BoardQueryStyle `json:"query_style,omitempty"`
// This field is required.
Dataset string `json:"dataset"`
// Either QueryID or Query is required.
QueryID string `json:"query_id,omitempty"`
Query *QuerySpec `json:"query,omitempty"`
// Optional
QueryAnnotationID string `json:"query_annotation_id,omitempty"`
}
// BoardQueryStyle determines how a query should be displayed on the board.
type BoardQueryStyle string
// Declaration of board query styles.
const (
BoardQueryStyleGraph BoardQueryStyle = "graph"
BoardQueryStyleTable BoardQueryStyle = "table"
BoardQueryStyleCombo BoardQueryStyle = "combo"
)
// BoardQueryStyles returns an exhaustive list of board query styles.
func BoardQueryStyles() []BoardQueryStyle {
return []BoardQueryStyle{BoardQueryStyleGraph, BoardQueryStyleTable, BoardQueryStyleCombo}
}
func (s *boards) List(ctx context.Context) ([]Board, error) {
var b []Board
err := s.client.performRequest(ctx, "GET", "/1/boards", nil, &b)
return b, err
}
func (s *boards) Get(ctx context.Context, ID string) (*Board, error) {
var b Board
err := s.client.performRequest(ctx, "GET", fmt.Sprintf("/1/boards/%s", ID), nil, &b)
return &b, err
}
func (s *boards) Create(ctx context.Context, data *Board) (*Board, error) {
var b Board
err := s.client.performRequest(ctx, "POST", "/1/boards", data, &b)
return &b, err
}
func (s *boards) Update(ctx context.Context, data *Board) (*Board, error) {
var b Board
err := s.client.performRequest(ctx, "PUT", fmt.Sprintf("/1/boards/%s", data.ID), data, &b)
return &b, err
}
func (s *boards) Delete(ctx context.Context, id string) error {
return s.client.performRequest(ctx, "DELETE", fmt.Sprintf("/1/boards/%s", id), nil, nil)
}