7009c705bb
parent 8d5586558c
author Galorhallen <andrea.ponte1987@gmail.com> 1640558190 +0100
committer Galorhallen <andrea.ponte1987@gmail.com> 1640821760 +0100
Add test for multiple pihole
Add async mode for multiple piholes
Fixed GitHub Actions go versions
Add test for multiple pihole
Cleanup
56 lines
1 KiB
Go
56 lines
1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/eko/pihole-exporter/config"
|
|
"github.com/eko/pihole-exporter/internal/metrics"
|
|
"github.com/eko/pihole-exporter/internal/pihole"
|
|
"github.com/eko/pihole-exporter/internal/server"
|
|
"github.com/xonvanetta/shutdown/pkg/shutdown"
|
|
)
|
|
|
|
func main() {
|
|
envConf, clientConfigs, err := config.Load()
|
|
if err != nil {
|
|
log.Fatal(err.Error())
|
|
}
|
|
|
|
metrics.Init()
|
|
|
|
serverDead := make(chan struct{})
|
|
|
|
clients := buildClients(clientConfigs)
|
|
|
|
s := server.NewServer(envConf.Port, clients)
|
|
go func() {
|
|
s.ListenAndServe()
|
|
close(serverDead)
|
|
}()
|
|
|
|
ctx := shutdown.Context()
|
|
|
|
go func() {
|
|
<-ctx.Done()
|
|
s.Stop()
|
|
}()
|
|
|
|
select {
|
|
case <-ctx.Done():
|
|
case <-serverDead:
|
|
}
|
|
|
|
fmt.Println("pihole-exporter HTTP server stopped")
|
|
}
|
|
|
|
func buildClients(clientConfigs []config.Config) []*pihole.Client {
|
|
clients := make([]*pihole.Client, 0, len(clientConfigs))
|
|
for i := range clientConfigs {
|
|
clientConfig := &clientConfigs[i]
|
|
|
|
client := pihole.NewClient(clientConfig)
|
|
clients = append(clients, client)
|
|
}
|
|
return clients
|
|
}
|