-
Notifications
You must be signed in to change notification settings - Fork 350
/
config.go
94 lines (69 loc) · 2.63 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
88
89
90
91
92
93
94
package relay
import (
"os"
"github.com/naoina/toml"
)
type Config struct {
HTTPRelays []HTTPConfig `toml:"http"`
UDPRelays []UDPConfig `toml:"udp"`
}
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"`
// Default retention policy to set for forwarded requests
DefaultRetentionPolicy string `toml:"default-retention-policy"`
// 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 UDPConfig struct {
// Name identifies the UDP relay
Name string `toml:"name"`
// Addr is where the UDP relay will listen for packets
Addr string `toml:"bind-addr"`
// Precision sets the precision of the timestamps (input and output)
Precision string `toml:"precision"`
// 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 []UDPOutputConfig `toml:"output"`
}
type UDPOutputConfig struct {
// Name identifies the UDP backend
Name string `toml:"name"`
// Location should be set to the host:port of the backend server
Location string `toml:"location"`
// MTU sets the maximum output payload size, default is 1024
MTU int `toml:"mtu"`
}
// 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)
}