From fa41e9c46c7b8fe6b0bda0a9584df9736f64a33a Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Thu, 8 Oct 2020 17:49:36 +0200 Subject: [PATCH] pkg/scope: add mutexes around scope (#33) --- pkg/scope/scope.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/scope/scope.go b/pkg/scope/scope.go index 84c31b1..585349e 100644 --- a/pkg/scope/scope.go +++ b/pkg/scope/scope.go @@ -7,7 +7,7 @@ import ( ) type Scope struct { - mu sync.Mutex + mu sync.RWMutex rules []Rule } @@ -31,6 +31,8 @@ func New(rules []Rule) *Scope { } func (s *Scope) Rules() []Rule { + s.mu.RLock() + defer s.mu.RUnlock() return s.rules } @@ -42,7 +44,8 @@ func (s *Scope) SetRules(rules []Rule) { } func (s *Scope) Match(req *http.Request, body []byte) bool { - // TODO(?): Do we need to lock here as well? + s.mu.RLock() + defer s.mu.RUnlock() for _, rule := range s.rules { if matches := rule.Match(req, body); matches { return true