-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
46 lines (43 loc) · 1.54 KB
/
config.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
package nscatools
type dataHandler func(*DataPacket) error
// Config manages the configuration of the client and server objects
type Config struct {
// When initiating a server, Host is the IP to listen on
// When initiating a client, Host is the target nsca host
Host string
// When initializing a server, Port is the port to listen on
// When initializing a client, Port is the port of the target nsca server
Port uint16
// Encryption methid to use based on the standard NSCA encryptions list
EncryptionMethod int
// Password is used to encypt and decrypt the messages if EncryptionMethod is
// not set to 0.
Password string
// Max size of each fields
MaxHostnameSize uint16
MaxDescriptionSize uint16
MaxPluginOutputSize uint16
// PacketHandler is the function that will handle the DataPacket in the
// HandleClient function. You define waht you want to do with the DataPacket
// once decrypted and transformed to a DataPacket struct.
// This function should follow this: func(*dataPacket) error
PacketHandler dataHandler
}
// NewConfig initiates a Config object (with default values if zero values given)
func NewConfig(host string, port uint16, encryption int, password string, handler dataHandler) *Config {
cfg := Config{
EncryptionMethod: encryption,
Password: password,
MaxHostnameSize: 64,
MaxDescriptionSize: 128,
MaxPluginOutputSize: 4096,
PacketHandler: handler,
}
if cfg.Host = "localhost"; host != "" {
cfg.Host = host
}
if cfg.Port = 5667; port != 0 {
cfg.Port = port
}
return &cfg
}