mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
Define service strings as consts to avoid forgetting to change them in all places
This commit is contained in:
parent
14bdcf71fe
commit
4c1165533c
@ -42,6 +42,12 @@ type dnsStatsWidget struct {
|
|||||||
Password string `yaml:"password"`
|
Password string `yaml:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
dnsServiceAdguard = "adguard"
|
||||||
|
dnsServicePihole = "pihole"
|
||||||
|
dnsServicePiholeV6 = "pihole-v6"
|
||||||
|
)
|
||||||
|
|
||||||
func makeDNSWidgetTimeLabels(format string) [8]string {
|
func makeDNSWidgetTimeLabels(format string) [8]string {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
var labels [dnsStatsBars]string
|
var labels [dnsStatsBars]string
|
||||||
@ -60,11 +66,11 @@ func (widget *dnsStatsWidget) initialize() error {
|
|||||||
withCacheDuration(10 * time.Minute)
|
withCacheDuration(10 * time.Minute)
|
||||||
|
|
||||||
switch widget.Service {
|
switch widget.Service {
|
||||||
case "adguard":
|
case dnsServiceAdguard:
|
||||||
case "pihole-v6":
|
case dnsServicePiholeV6:
|
||||||
case "pihole":
|
case dnsServicePihole:
|
||||||
default:
|
default:
|
||||||
return errors.New("service must be one of: adguard, pihole-v6, pihole")
|
return fmt.Errorf("service must be one of: %s, %s, %s", dnsServiceAdguard, dnsServicePihole, dnsServicePiholeV6)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -75,11 +81,11 @@ func (widget *dnsStatsWidget) update(ctx context.Context) {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
switch widget.Service {
|
switch widget.Service {
|
||||||
case "adguard":
|
case dnsServiceAdguard:
|
||||||
stats, err = fetchAdguardStats(widget.URL, widget.AllowInsecure, widget.Username, widget.Password, widget.HideGraph)
|
stats, err = fetchAdguardStats(widget.URL, widget.AllowInsecure, widget.Username, widget.Password, widget.HideGraph)
|
||||||
case "pihole":
|
case dnsServicePihole:
|
||||||
stats, err = fetchPihole5Stats(widget.URL, widget.AllowInsecure, widget.Token, widget.HideGraph)
|
stats, err = fetchPihole5Stats(widget.URL, widget.AllowInsecure, widget.Token, widget.HideGraph)
|
||||||
case "pihole6":
|
case dnsServicePiholeV6:
|
||||||
var newSessionID string
|
var newSessionID string
|
||||||
stats, newSessionID, err = fetchPiholeStats(
|
stats, newSessionID, err = fetchPiholeStats(
|
||||||
widget.URL,
|
widget.URL,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user