-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
60 lines (49 loc) · 1.2 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
package gopii_test
import (
"fmt"
"github.com/blizzy78/gopii"
)
func Example_string() {
// define string part types
const (
typePlain = gopii.PartType(iota + 1)
typeLogin
typePassword
)
// define output levels
const (
levelInternal = gopii.Level(iota + 1)
levelDevLog
levelProdLog
levelWorld
)
// define how to obscure each part type at each output level -
// higher levels are obscured more restrictively
obscure := map[gopii.PartType]map[gopii.Level]gopii.ObscureFunc{
// plain text is never obscured
typePlain: {levelWorld: gopii.Plain()},
typeLogin: {
levelInternal: gopii.Plain(),
levelDevLog: gopii.KeepFirstLast(2, 2),
levelProdLog: gopii.KeepFirst(1),
},
typePassword: {
levelInternal: gopii.Plain(),
levelDevLog: gopii.KeepFirst(3),
},
}
// create a new string with parts of different types
str := gopii.NewString(obscure,
"JohnDoe", typeLogin,
":", typePlain,
"secret", typePassword,
)
// for each output level, print the string with the appropriate obscuring
fmt.Println(str.String(levelInternal))
fmt.Println(str.String(levelDevLog))
fmt.Println(str.String(levelProdLog))
// Output:
// JohnDoe:secret
// Jo***oe:sec***
// J***:***
}