Skip to content

Commit 30c2610

Browse files
committed
refactor: reduce complexity of shouldTrack
1 parent 823e9d9 commit 30c2610

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

umami.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ func (h *UmamiFeeder) verifyConfig(config *Config) error {
303303
return nil
304304
}
305305

306-
func (h *UmamiFeeder) shouldTrack(req *http.Request) bool {
306+
func (h *UmamiFeeder) shouldTrackRequest(req *http.Request) bool {
307307
if len(h.ignoreHosts) > 0 {
308308
for _, disabledHost := range h.ignoreHosts {
309309
if strings.EqualFold(req.Host, disabledHost) {
@@ -353,6 +353,14 @@ func (h *UmamiFeeder) shouldTrack(req *http.Request) bool {
353353
}
354354
}
355355

356+
return true
357+
}
358+
359+
func (h *UmamiFeeder) shouldTrack(req *http.Request) bool {
360+
if !h.shouldTrackRequest(req) {
361+
return false
362+
}
363+
356364
if !h.shouldTrackResource(req.URL.Path) {
357365
h.debugf("ignoring resource %s", req.URL.Path)
358366
return false

umami_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func assertIgnoreIP(t *testing.T, plugin *UmamiFeeder, expected bool, clientIP s
8888
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://localhost", nil)
8989
req.Header.Set(plugin.headerIp, clientIP)
9090

91-
if expected != plugin.shouldTrack(req) {
91+
if expected != plugin.shouldTrackRequest(req) {
9292
t.Fatalf("expected %v for %s", expected, clientIP)
9393
}
9494
}
@@ -125,7 +125,7 @@ func assertIgnoreUrl(t *testing.T, plugin *UmamiFeeder, expected bool, url strin
125125
t.Helper()
126126
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil)
127127

128-
if expected != plugin.shouldTrack(req) {
128+
if expected != plugin.shouldTrackRequest(req) {
129129
t.Fatalf("expected %v for %s", expected, url)
130130
}
131131
}
@@ -148,7 +148,7 @@ func assertIgnoreUa(t *testing.T, plugin *UmamiFeeder, expected bool, ua string)
148148
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "http://localhost/", nil)
149149
req.Header.Set("User-Agent", ua)
150150

151-
if expected != plugin.shouldTrack(req) {
151+
if expected != plugin.shouldTrackRequest(req) {
152152
t.Fatalf("expected %v for %s", expected, ua)
153153
}
154154
}

0 commit comments

Comments
 (0)