summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatthieu <matthieu.cneude@gmail.com>2021-02-20 18:54:25 +0100
committermatthieu <matthieu.cneude@gmail.com>2021-02-20 18:54:25 +0100
commit34cc7885f7e27e3986ad69cfe4475f541d451fd6 (patch)
tree4eeee03c6b040b6b4546f8e54d35495a0d110011
parent2f3f8bcf3a059d464b42a3262e0b10c59ac8be27 (diff)
Add the possibility to monitor a different website by address
-rw-r--r--gokit/math.go4
-rw-r--r--internal/monitor_widget.go15
-rw-r--r--internal/widget.go3
3 files changed, 18 insertions, 4 deletions
diff --git a/gokit/math.go b/gokit/math.go
index 2cb17ba..d76cfc3 100644
--- a/gokit/math.go
+++ b/gokit/math.go
@@ -2,8 +2,8 @@ package gokit
import "math"
-// good old utiles stuff
-// expand the go language (ONLY very very general abstractions)
+// ONLY very general abstractions
+// which doesn't change with the messy world
func Round(n float64, precision int) (r float64) {
pow := math.Pow(10, float64(precision))
diff --git a/internal/monitor_widget.go b/internal/monitor_widget.go
index c18f7d4..570ffd0 100644
--- a/internal/monitor_widget.go
+++ b/internal/monitor_widget.go
@@ -43,7 +43,13 @@ func (m *monitorWidget) CreateWidgets(widget Widget, tui *Tui) (f func() error,
}
func (m *monitorWidget) pingWidget(widget Widget) (f func() error, err error) {
- URL, err := url.Parse(m.address)
+ u := m.address
+
+ if _, ok := widget.Options[optionAddress]; ok {
+ u = widget.Options[optionAddress]
+ }
+
+ URL, err := url.Parse(u)
if err != nil {
return nil, err
}
@@ -73,7 +79,12 @@ func (m *monitorWidget) pingWidget(widget Widget) (f func() error, err error) {
}
func (m *monitorWidget) availabilityWidget(widget Widget) (f func() error, err error) {
- req, err := http.NewRequest(http.MethodGet, m.address, nil)
+ u := m.address
+ if _, ok := widget.Options[optionAddress]; ok {
+ u = widget.Options[optionAddress]
+ }
+
+ req, err := http.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, err
}
diff --git a/internal/widget.go b/internal/widget.go
index 3df972a..6f818fb 100644
--- a/internal/widget.go
+++ b/internal/widget.go
@@ -10,6 +10,9 @@ const (
optionTitle = "title"
optionTitleColor = "title_color"
+ // Monitor
+ optionAddress = "address"
+
// Time
optionStartDate = "start_date"
optionEndDate = "end_date"