Skip to content

Commit 4c11655

Browse files
committed
Define service strings as consts to avoid forgetting to change them in all places
1 parent 14bdcf7 commit 4c11655

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

internal/glance/widget-dns-stats.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ type dnsStatsWidget struct {
4242
Password string `yaml:"password"`
4343
}
4444

45+
const (
46+
dnsServiceAdguard = "adguard"
47+
dnsServicePihole = "pihole"
48+
dnsServicePiholeV6 = "pihole-v6"
49+
)
50+
4551
func makeDNSWidgetTimeLabels(format string) [8]string {
4652
now := time.Now()
4753
var labels [dnsStatsBars]string
@@ -60,11 +66,11 @@ func (widget *dnsStatsWidget) initialize() error {
6066
withCacheDuration(10 * time.Minute)
6167

6268
switch widget.Service {
63-
case "adguard":
64-
case "pihole-v6":
65-
case "pihole":
69+
case dnsServiceAdguard:
70+
case dnsServicePiholeV6:
71+
case dnsServicePihole:
6672
default:
67-
return errors.New("service must be one of: adguard, pihole-v6, pihole")
73+
return fmt.Errorf("service must be one of: %s, %s, %s", dnsServiceAdguard, dnsServicePihole, dnsServicePiholeV6)
6874
}
6975

7076
return nil
@@ -75,11 +81,11 @@ func (widget *dnsStatsWidget) update(ctx context.Context) {
7581
var err error
7682

7783
switch widget.Service {
78-
case "adguard":
84+
case dnsServiceAdguard:
7985
stats, err = fetchAdguardStats(widget.URL, widget.AllowInsecure, widget.Username, widget.Password, widget.HideGraph)
80-
case "pihole":
86+
case dnsServicePihole:
8187
stats, err = fetchPihole5Stats(widget.URL, widget.AllowInsecure, widget.Token, widget.HideGraph)
82-
case "pihole6":
88+
case dnsServicePiholeV6:
8389
var newSessionID string
8490
stats, newSessionID, err = fetchPiholeStats(
8591
widget.URL,

0 commit comments

Comments
 (0)