-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
70 lines (56 loc) · 1.92 KB
/
client.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
package api
import (
"net/http"
)
// APIClient is the method set required for any API sending data into a Geneos Netprobe
type APIClient interface {
Healthy() bool
CreateDataview(entity, sampler, name string) error
UpdateDataview(entity, sampler, name string, values [][]string) error
DeleteDataview(entity, sampler, name string) error
CreateRow(entity, sampler, view, name string) error
UpdateRow(entity, sampler, view, name string, values []string) error
DeleteRow(entity, sampler, view, name string) error
CreateColumn(entity, sampler, view, name string) error
CreateHeadline(entity, sampler, view, name string) error
UpdateHeadline(entity, sampler, view, name, value string) error
DeleteHeadline(entity, sampler, view, name string) error
CreateStream(entity, sampler, name string) error
UpdateStream(entity, sampler, name string, message any) error
ManagedEntityExists(entity string) (bool, error)
SamplerExists(entity, sampler string) (bool, error)
DataviewExists(entity, sampler, name string) (bool, error)
ColumnExists(entity, sampler, view, name string) (bool, error)
RowExists(entity, sampler, view, name string) (bool, error)
HeadlineExists(entity, sampler, view, name string) (bool, error)
}
type roundTripper struct {
transport http.RoundTripper
}
func (r *roundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
return r.transport.RoundTrip(req)
}
// compile time check for interface validity
var _ http.RoundTripper = (*roundTripper)(nil)
type Stream struct {
client APIClient
entity string
sampler string
stream string
}
func OpenStream(c APIClient, entity, sampler, stream string) (s *Stream, err error) {
s = &Stream{
client: c,
entity: entity,
sampler: sampler,
stream: stream,
}
return
}
func (s *Stream) Write(data []byte) (n int, err error) {
if err = s.client.UpdateStream(s.entity, s.sampler, s.stream, string(data)); err != nil {
return
}
n = len(data)
return
}