forked from StephanU/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
32 lines (27 loc) · 972 Bytes
/
util.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
package outputs
// Fail helper can be used by output factories, to create a failure response when
// loading an output must return an error.
func Fail(err error) (Group, error) { return Group{}, err }
// Success create a valid output Group response for a set of client instances.
func Success(batchSize, retry int, clients ...Client) (Group, error) {
return Group{
Clients: clients,
BatchSize: batchSize,
Retry: retry,
}, nil
}
// NetworkClients converts a list of NetworkClient instances into []Client.
func NetworkClients(netclients []NetworkClient) []Client {
clients := make([]Client, len(netclients))
for i, n := range netclients {
clients[i] = n
}
return clients
}
func SuccessNet(loadbalance bool, batchSize, retry int, netclients []NetworkClient) (Group, error) {
if !loadbalance {
return Success(batchSize, retry, NewFailoverClient(netclients))
}
clients := NetworkClients(netclients)
return Success(batchSize, retry, clients...)
}