-
Notifications
You must be signed in to change notification settings - Fork 289
/
mux.go
47 lines (40 loc) · 946 Bytes
/
mux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package replacer
import (
"errors"
)
// Mux contains multiple replacers
type Mux struct {
underlying []*Replacer
}
// NewMux returns a new mux with the given replacers.
func NewMux(rs ...*Replacer) *Mux {
m := &Mux{
underlying: make([]*Replacer, 0, len(rs)),
}
m.underlying = append(m.underlying, rs...)
return m
}
// Reset resets all replacers with new needles (secrets).
func (m *Mux) Reset(needles []string) {
for _, r := range m.underlying {
r.Reset(needles)
}
}
// Add adds needles to all replacers.
func (m *Mux) Add(needles ...string) {
for _, r := range m.underlying {
r.Add(needles...)
}
}
// Append adds a replacer to the Mux.
func (m *Mux) Append(r *Replacer) {
m.underlying = append(m.underlying, r)
}
// Flush flushes all replacers.
func (m *Mux) Flush() error {
errs := make([]error, 0, len(m.underlying))
for _, r := range m.underlying {
errs = append(errs, r.Flush())
}
return errors.Join(errs...)
}