-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (45 loc) · 1.17 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
49
50
51
52
53
54
package main
import (
"context"
"log"
"github.com/cguertin14/ddns/pkg/cloudflare"
"github.com/cguertin14/ddns/pkg/config"
"github.com/cguertin14/ddns/pkg/ddns"
gh "github.com/cguertin14/ddns/pkg/github"
"github.com/cguertin14/logger"
)
func main() {
cfg, err := config.Load()
if err != nil {
log.Fatalf("failed to load config: %s\n", err)
}
// initialize logger
appLogger := logger.Initialize(logger.Config{
Level: cfg.LogLevel,
Formatter: logger.ServiceFormatter,
})
ctx := context.WithValue(context.Background(), logger.CtxKey, appLogger)
// cloudflare client
cfClient, err := cloudflare.NewClient(cfg.CloudflareToken)
if err != nil {
appLogger.Fatalln(err)
}
// github client
ghClient := gh.NewClient(ctx, cfg.GithubToken)
// initialize app
app := ddns.NewClient(ddns.Dependencies{
Cloudflare: cfClient,
Github: ghClient,
})
// run app
report, err := app.Run(ctx, *cfg)
if err != nil {
appLogger.Fatalf("failed to run app: %s\n", err)
}
// success message
if report.DnsChanged {
appLogger.Infof("Successfully updated DNS Record %q to %q.\n", cfg.RecordName, report.NewIP)
} else {
appLogger.Infoln("DNS record unchanged.")
}
}