package monitor import ( "strconv" "strings" "time" ) type viewBag struct { title string refresh time.Duration fontURL string chartJSURL string customHead string } // returns index with new title/refresh func newIndex(dat viewBag) string { timeout := dat.refresh.Milliseconds() - timeoutDiff if timeout < timeoutDiff { timeout = timeoutDiff } ts := strconv.FormatInt(timeout, 10) replacer := strings.NewReplacer("$TITLE", dat.title, "$TIMEOUT", ts, "$FONT_URL", dat.fontURL, "$CHART_JS_URL", dat.chartJSURL, "$CUSTOM_HEAD", dat.customHead, ) return replacer.Replace(indexHTML) } const ( defaultTitle = "Fiber Monitor" defaultRefresh = 3 * time.Second timeoutDiff = 200 // timeout will be Refresh (in milliseconds) - timeoutDiff minRefresh = timeoutDiff * time.Millisecond defaultFontURL = `https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&display=swap` defaultChartJSURL = `https://cdn.jsdelivr.net/npm/chart.js@2.9/dist/Chart.bundle.min.js` defaultCustomHead = `` // parametrized by $TITLE and $TIMEOUT indexHTML = ` $TITLE

$TITLE

CPU Usage

0.00%

Memory Usage

0.00 MB

Response Time

0ms

Open Connections

0

` )