Files
ddns-updater/pkg/models/html.go
Quentin McGaw ed1823d244 Complete code refactoring
- `LOGGING` environment variable `json` or `human`
- `NODEID` environment variable (integer)
- Much cleaner go code
- Listener for exit of program to do cleanup
- All code is in packages except main.go
- Custom logger package added
- Connectivity checks reworked
- Healthcheck server on localhost only, so not exposed to outside world
- Updated `go.mod` and `go.sum`
2019-04-26 02:04:39 +02:00

46 lines
1.2 KiB
Go

package models
import (
"fmt"
"time"
)
// HTMLData is a list of HTML fields to be rendered.
// It is exported so that the HTML template engine can render it.
type HTMLData struct {
Rows []HTMLRow
}
// HTMLRow contains HTML fields to be rendered
// It is exported so that the HTML template engine can render it.
type HTMLRow struct {
Domain string
Host string
Provider string
IPMethod string
Status string
IP string // current set ip
IPs []string // previous ips
}
// ToHTML converts all the update record configs to HTML data ready to be templated
func ToHTML(recordsConfigs []RecordConfigType) (htmlData HTMLData) {
for i := range recordsConfigs {
htmlData.Rows = append(htmlData.Rows, recordsConfigs[i].toHTML())
}
return htmlData
}
func durationString(t time.Time) string {
duration := time.Since(t)
if duration < time.Minute {
return fmt.Sprintf("%ds", int(duration.Round(time.Second).Seconds()))
} else if duration < time.Hour {
return fmt.Sprintf("%dm", int(duration.Round(time.Minute).Minutes()))
} else if duration < 24*time.Hour {
return fmt.Sprintf("%dh", int(duration.Round(time.Hour).Hours()))
} else {
return fmt.Sprintf("%dd", int(duration.Round(time.Hour*24).Hours()/24))
}
}