-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.go
45 lines (34 loc) · 823 Bytes
/
update.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
package main
import (
"fmt"
"net"
"github.com/gin-gonic/gin"
)
type UpdateHandler struct {
settings *Settings
client *DynClient
}
func NewUpdateHandler(settings *Settings, client *DynClient) *UpdateHandler {
return &UpdateHandler{settings, client}
}
func (h *UpdateHandler) Handle(c *gin.Context) {
ip := net.ParseIP(c.Query("myip"))
if ip == nil {
c.String(400, "Please specify your IP address.")
return
}
successfulUpdates := 0
for _, record := range h.settings.Records {
body, loggingUrl, err := h.client.Update(record, ip)
if err != nil {
c.Error(err)
continue
}
successfulUpdates++
fmt.Print(loggingUrl)
fmt.Println(":")
fmt.Print("\t")
fmt.Println(string(body))
}
c.String(200, "Successfully updated %d of %d records", successfulUpdates, len(h.settings.Records))
}