summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/pkg/socket/types.go
blob: 693faf5be1f6120d224526ff7f02f7916fc72f68 (plain)
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
// SPDX-License-Identifier: GPL-3.0-or-later

package socket

import (
	"crypto/tls"
	"time"
)

// Processor function passed to the Socket.Command function.
// It is passed by the caller to process a command's response
// line by line.
type Processor func([]byte) bool

// Client is the interface that wraps the basic socket client operations
// and hides the implementation details from the users.
//
// Connect should prepare the connection.
//
// Disconnect should stop any in-flight connections.
//
// Command should send the actual data to the wire and pass
// any results to the processor function.
//
// Implementations should return TCP, UDP or Unix ready sockets.
type Client interface {
	Connect() error
	Disconnect() error
	Command(command string, process Processor) error
}

// Config holds the network ip v4 or v6 address, port,
// Socket type(ip, tcp, udp, unix), timeout and TLS configuration
// for a Socket
type Config struct {
	Address        string
	ConnectTimeout time.Duration
	ReadTimeout    time.Duration
	WriteTimeout   time.Duration
	TLSConf        *tls.Config
}