Removed 'interval' configuration. Add timeout

This commit is contained in:
Galorhallen 2022-01-05 22:05:32 +01:00
parent 2a939bf754
commit 4381338fae
3 changed files with 7 additions and 6 deletions

View file

@ -31,7 +31,7 @@ type EnvConfig struct {
PIHolePassword []string `config:"pihole_password"` PIHolePassword []string `config:"pihole_password"`
PIHoleApiToken []string `config:"pihole_api_token"` PIHoleApiToken []string `config:"pihole_api_token"`
Port uint16 `config:"port"` Port uint16 `config:"port"`
Interval time.Duration `config:"interval"` Timeout time.Duration `config:"timeout"`
} }
func getDefaultEnvConfig() *EnvConfig { func getDefaultEnvConfig() *EnvConfig {
@ -42,7 +42,7 @@ func getDefaultEnvConfig() *EnvConfig {
PIHolePassword: []string{}, PIHolePassword: []string{},
PIHoleApiToken: []string{}, PIHoleApiToken: []string{},
Port: 9617, Port: 9617,
Interval: 10 * time.Second, Timeout: 5 * time.Second,
} }
} }

View file

@ -51,7 +51,7 @@ type Client struct {
} }
// NewClient method initializes a new PI-Hole client. // NewClient method initializes a new PI-Hole client.
func NewClient(config *config.Config) *Client { func NewClient(config *config.Config, envConfig *config.EnvConfig) *Client {
err := config.Validate() err := config.Validate()
if err != nil { if err != nil {
log.Print(err) log.Print(err)
@ -66,6 +66,7 @@ func NewClient(config *config.Config) *Client {
CheckRedirect: func(req *http.Request, via []*http.Request) error { CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse return http.ErrUseLastResponse
}, },
Timeout: envConfig.Timeout,
}, },
Status: make(chan *ClientChannel, 1), Status: make(chan *ClientChannel, 1),
} }

View file

@ -20,7 +20,7 @@ func main() {
serverDead := make(chan struct{}) serverDead := make(chan struct{})
clients := buildClients(clientConfigs) clients := buildClients(clientConfigs, envConf)
s := server.NewServer(envConf.Port, clients) s := server.NewServer(envConf.Port, clients)
go func() { go func() {
@ -43,12 +43,12 @@ func main() {
log.Println("pihole-exporter HTTP server stopped") log.Println("pihole-exporter HTTP server stopped")
} }
func buildClients(clientConfigs []config.Config) []*pihole.Client { func buildClients(clientConfigs []config.Config, envConfig *config.EnvConfig) []*pihole.Client {
clients := make([]*pihole.Client, 0, len(clientConfigs)) clients := make([]*pihole.Client, 0, len(clientConfigs))
for i := range clientConfigs { for i := range clientConfigs {
clientConfig := &clientConfigs[i] clientConfig := &clientConfigs[i]
client := pihole.NewClient(clientConfig) client := pihole.NewClient(clientConfig, envConfig)
clients = append(clients, client) clients = append(clients, client)
} }
return clients return clients