mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
pkg/scope: add mutexes around scope (#33)
This commit is contained in:

committed by
GitHub

parent
5f4bff0155
commit
fa41e9c46c
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Scope struct {
|
type Scope struct {
|
||||||
mu sync.Mutex
|
mu sync.RWMutex
|
||||||
rules []Rule
|
rules []Rule
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +31,8 @@ func New(rules []Rule) *Scope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scope) Rules() []Rule {
|
func (s *Scope) Rules() []Rule {
|
||||||
|
s.mu.RLock()
|
||||||
|
defer s.mu.RUnlock()
|
||||||
return s.rules
|
return s.rules
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +44,8 @@ func (s *Scope) SetRules(rules []Rule) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scope) Match(req *http.Request, body []byte) bool {
|
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 {
|
for _, rule := range s.rules {
|
||||||
if matches := rule.Match(req, body); matches {
|
if matches := rule.Match(req, body); matches {
|
||||||
return true
|
return true
|
||||||
|
Reference in New Issue
Block a user