-
Notifications
You must be signed in to change notification settings - Fork 0
/
mask.go
29 lines (26 loc) · 919 Bytes
/
mask.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
package sensitive
import "github.com/ln80/struct-sensitive/mask"
// WithRegisteredMasks returns an option that force redaction using the registered masks,
// including the predefined one e.g. `email`, `ipv4_addr`, `credit_card`.
//
// Use [mask.Register] to override or register new masks.
func WithRegisteredMasks(rc *RedactConfig) {
rc.RedactFunc = func(fr FieldReplace, val string) (string, error) {
if fr.Kind == "" {
return RedactDefaultFunc(fr, val)
}
m, ok := mask.Of(fr.Kind)
if !ok {
return RedactDefaultFunc(fr, val)
}
return m(val)
}
}
// Mask partially redacts sensitive data based on their type (aka kind).
//
// It is simply a facade function that calls [Redact] with [WithRegisteredMasks] option.
//
// Use [mask.Register] to register additional masks.
func Mask(structPtr any, opts ...func(*RedactConfig)) error {
return Redact(structPtr, append(opts, WithRegisteredMasks)...)
}