-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
54 lines (41 loc) · 935 Bytes
/
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 (
"fmt"
"github.com/gin-gonic/gin"
)
func main() {
settings, err := LoadSettings()
if err != nil {
fmt.Println(err)
return
}
client := NewDynClient(settings.UserAgent)
UpdateOnStartup(settings, client)
router := gin.Default()
router.Use(gin.Logger())
router.GET("/update", NewAuthHandler(settings).Handle, NewUpdateHandler(settings, client).Handle)
router.Run(settings.ListenerAddress)
}
func UpdateOnStartup(settings *Settings, client *DynClient) {
if len(settings.IpRetrieveUrl) == 0 {
return
}
ip, err := client.GetExternalIp(settings.IpRetrieveUrl)
if err != nil {
fmt.Println(err)
return
}
if settings.UpdateOnStartup {
for _, record := range settings.Records {
body, loggingUrl, err := client.Update(record, ip)
fmt.Print(loggingUrl)
fmt.Println(":")
fmt.Print("\t")
if err == nil {
fmt.Println(body)
} else {
fmt.Println(err)
}
}
}
}