-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
66 lines (54 loc) · 1.84 KB
/
example_test.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package redact
import (
"fmt"
)
func ExampleSecret_Redact() {
// Censor example: simple word
data := []byte("There is a secret word here")
s := NewSecret("secret", Censor, []byte("#REDACTED#"))
fmt.Println(string(s.Redact(data)))
// BlackOut example: regular expression
data = []byte("These are a couple of CPFs: 321.654.987-00 and 789.456.123-00")
s = NewSecret(`[0-9]{3}\.[0-9]{3}\.[0-9]{3}-[0-9]{2}`, BlackOut, []byte("█"))
fmt.Println(string(s.Redact(data)))
// ReplaceData example
data = []byte("Something about the government")
s = NewSecret("government", ReplaceData, []byte("Text about flowers"))
fmt.Println(string(s.Redact(data)))
// Output:
// There is a #REDACTED# word here
// These are a couple of CPFs: ██████████████ and ██████████████
// Text about flowers
}
func ExampleInquiry_Redact() {
bo := []byte("█")
inq := New()
inq.AddSecretValue(NewSecret("secret[s]?", BlackOut, bo))
inq.AddSecretValue(NewSecret("SSN", BlackOut, []byte("")))
inq.AddSecretValue(NewSecret(
`[1-9]{3}-[1-9]{2}-[1-9]{4}`, BlackOut, bo))
inq.AddSecretField("date")
inq.AddSecretField("^SSN$")
// Redact text example
data := []byte(`This text has more than one type of secret. Here is someone's SSN 987-65-4321`)
r, err := inq.Redact(data)
if err != nil {
// Handle error
}
fmt.Println(string(r))
// Redact JSON example
data = []byte(`{
"Name":"Wilson",
"create_date": "2020-08-31 15:51:14+00:00",
"modify_date": "2020-08-31 15:52:15+00:00",
"SSN": "123-45-6789",
"quote": "We all have secrets"}`)
r, err = inq.Redact(data)
if err != nil {
// Handle error
}
fmt.Println(string(r))
// Output:
// This text has more than one type of ██████. Here is someone's ███████████
// {"Name":"Wilson","quote":"We all have ███████"}
}