diff --git a/config/configuration.go b/config/configuration.go index 7fa1438..450bc50 100644 --- a/config/configuration.go +++ b/config/configuration.go @@ -31,7 +31,7 @@ type EnvConfig struct { PIHolePassword []string `config:"pihole_password"` PIHoleApiToken []string `config:"pihole_api_token"` Port uint16 `config:"port"` - Interval time.Duration `config:"interval"` + Timeout time.Duration `config:"timeout"` } func getDefaultEnvConfig() *EnvConfig { @@ -42,7 +42,7 @@ func getDefaultEnvConfig() *EnvConfig { PIHolePassword: []string{}, PIHoleApiToken: []string{}, Port: 9617, - Interval: 10 * time.Second, + Timeout: 5 * time.Second, } } diff --git a/internal/pihole/client.go b/internal/pihole/client.go index 4cb6f64..867e547 100644 --- a/internal/pihole/client.go +++ b/internal/pihole/client.go @@ -51,7 +51,7 @@ type Client struct { } // 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() if err != nil { log.Print(err) @@ -66,6 +66,7 @@ func NewClient(config *config.Config) *Client { CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, + Timeout: envConfig.Timeout, }, Status: make(chan *ClientChannel, 1), } diff --git a/main.go b/main.go index 1adb3de..ad37555 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,7 @@ func main() { serverDead := make(chan struct{}) - clients := buildClients(clientConfigs) + clients := buildClients(clientConfigs, envConf) s := server.NewServer(envConf.Port, clients) go func() { @@ -43,12 +43,12 @@ func main() { 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)) for i := range clientConfigs { clientConfig := &clientConfigs[i] - client := pihole.NewClient(clientConfig) + client := pihole.NewClient(clientConfig, envConfig) clients = append(clients, client) } return clients