/
config.go
87 lines (65 loc) · 2.39 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package relay
import (
"github.com/naoina/toml"
"os"
)
type Config struct {
HTTPRelays []HTTPConfig `toml:"http"`
//TCPRelays []TCPConfig `toml:"tcp"`
}
type HTTPConfig struct {
// Name identifies the HTTP relay
Name string `toml:"name"`
// Addr should be set to the desired listening host:port
Addr string `toml:"bind-addr"`
// Set certificate in order to handle HTTPS requests
SSLCombinedPem string `toml:"ssl-combined-pem"`
// Persistent buffer path
BufferDir string `toml:"buffer-dir"`
// Outputs is a list of backed servers where writes will be forwarded
Outputs []HTTPOutputConfig `toml:"output"`
}
type HTTPOutputConfig struct {
// Name of the backend server
Name string `toml:"name"`
// Location should be set to the URL of the backend server's write endpoint
Location string `toml:"location"`
// Timeout sets a per-backend timeout for write requests. (Default 10s)
// The format used is the same seen in time.ParseDuration
Timeout string `toml:"timeout"`
// Buffer failed writes up to maximum count. (Default 0, retry/buffering disabled)
//BufferSizeMB int `toml:"buffer-size-mb"`
// Maximum batch size in KB (Default 512)
//MaxBatchKB int `toml:"max-batch-kb"`
// Maximum delay between retry attempts.
// The format used is the same seen in time.ParseDuration (Default 10s)
//MaxDelayInterval string `toml:"max-delay-interval"`
// Skip TLS verification in order to use self signed certificate.
// WARNING: It's insecure. Use it only for developing and don't use in production.
SkipTLSVerification bool `toml:"skip-tls-verification"`
}
type TCPConfig struct {
// Name identifies the TCP relay
Name string `toml:"name"`
// Addr is where the TCP relay will listen for packets
Addr string `toml:"bind-addr"`
// ReadBuffer sets the socket buffer for incoming connections
//ReadBuffer int `toml:"read-buffer"`
// Outputs is a list of backend servers where writes will be forwarded
Outputs []TCPOutputConfig `toml:"output"`
}
type TCPOutputConfig struct {
// Name identifies the TCP backend
Name string `toml:"name"`
// Location should be set to the host:port of the backend server
Location string `toml:"location"`
}
// LoadConfigFile parses the specified file into a Config object
func LoadConfigFile(filename string) (cfg Config, err error) {
f, err := os.Open(filename)
if err != nil {
return cfg, err
}
defer f.Close()
return cfg, toml.NewDecoder(f).Decode(&cfg)
}