-
Notifications
You must be signed in to change notification settings - Fork 11
/
client.go
63 lines (51 loc) · 1.29 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
// A Riemann client for Go, featuring concurrency, sending events and state updates, queries
//
// Copyright (C) 2014 by Christopher Gilbert <[email protected]>
package riemanngo
import (
"github.com/riemann/riemann-go-client/proto"
)
// Client is an interface to a generic client
type Client interface {
Send(message *proto.Msg) (*proto.Msg, error)
Connect() error
Close() error
}
// IndexClient is an interface to a generic Client for index queries
type IndexClient interface {
QueryIndex(q string) ([]Event, error)
}
// request encapsulates a request to send to the Riemann server
type request struct {
message *proto.Msg
responseCh chan response
}
// response encapsulates a response from the Riemann server
type response struct {
message *proto.Msg
err error
}
// SendEvent send an event using a client
func SendEvent(c Client, e *Event) (*proto.Msg, error) {
return SendEvents(
c, &([]Event{*e}),
)
}
// SendEvents send multiple events using a client
func SendEvents(c Client, e *[]Event) (*proto.Msg, error) {
buff := make(
[]*proto.Event, len(*e),
)
for i, elem := range *e {
epb, err := EventToProtocolBuffer(
&elem,
)
if err != nil {
return nil, err
}
buff[i] = epb
}
message := new(proto.Msg)
message.Events = buff
return c.Send(message)
}