Move behavior within the widget init

Otherwise we create a global getWidgetTitleURL
function that sounds a little too generic and vague
This commit is contained in:
Svilen Markov 2025-03-18 13:11:19 +00:00
parent 55685e6854
commit a77d0ce5c0

View File

@ -60,19 +60,16 @@ func makeDNSWidgetTimeLabels(format string) [8]string {
return labels
}
func getWidgetTitleURL(widget *dnsStatsWidget) string {
func (widget *dnsStatsWidget) initialize() error {
titleURL := strings.TrimRight(widget.URL, "/")
switch widget.Service {
case dnsServicePihole, dnsServicePiholeV6:
return fmt.Sprintf("%s/admin", strings.TrimRight(widget.URL, "/"))
default:
return widget.URL
titleURL = titleURL + "/admin"
}
}
func (widget *dnsStatsWidget) initialize() error {
widget.
withTitle("DNS Stats").
withTitleURL(getWidgetTitleURL(widget)).
withTitleURL(titleURL).
withCacheDuration(10 * time.Minute)
switch widget.Service {