-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (38 loc) · 1.2 KB
/
main.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
package main
import (
"net/http"
"os"
"github.com/davidborzek/hetzner-ddns-updater/internal/config"
"github.com/davidborzek/hetzner-ddns-updater/internal/ddns"
"github.com/davidborzek/hetzner-ddns-updater/internal/handler"
"github.com/davidborzek/hetzner-ddns-updater/internal/metrics"
"github.com/davidborzek/hetzner-ddns-updater/pkg/hetzner"
"github.com/davidborzek/hetzner-ddns-updater/pkg/publicip"
"github.com/davidborzek/hetzner-ddns-updater/pkg/scheduler"
log "github.com/sirupsen/logrus"
)
func main() {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
log.WithField("pid", os.Getpid()).
Info("starting hetzner-ddns-updater")
cfg, err := config.Load()
if err != nil {
log.WithError(err).
Fatal("failed to load config")
}
if cfg.MetricsEnabled {
metrics.EnableMetrics()
}
publicip.SetProviderURL(cfg.PublicIPProvider)
updater := ddns.NewUpdater(cfg, hetzner.New(cfg.ApiToken))
go scheduler.Schedule(cfg.Interval, updater.Update)
log.WithField("addr", cfg.Address).
Info("starting the http server")
h := handler.NewHandler(cfg)
if err := http.ListenAndServe(cfg.Address, h.Handle()); err != nil {
log.WithError(err).
Fatalf("failed to start http server")
}
}