maskValue 创建掩码值
(value string, maskLength int)
| 100 | |
| 101 | // maskValue 创建掩码值 |
| 102 | func (r *PIIRedactor) maskValue(value string, maskLength int) string { |
| 103 | if value == "" { |
| 104 | return value |
| 105 | } |
| 106 | |
| 107 | if maskLength <= 0 { |
| 108 | return strings.Repeat("*", len(value)) |
| 109 | } |
| 110 | |
| 111 | if len(value) <= maskLength { |
| 112 | return strings.Repeat("*", len(value)) |
| 113 | } |
| 114 | |
| 115 | // 保留首尾字符,中间用*替换 |
| 116 | end := len(value) - 1 |
| 117 | if len(value) <= 2 { |
| 118 | return strings.Repeat("*", len(value)) |
| 119 | } |
| 120 | |
| 121 | masked := string(value[0]) + strings.Repeat("*", maskLength) + string(value[end]) |
| 122 | return masked |
| 123 | } |
| 124 | |
| 125 | // AddCustomPIIType 添加自定义PII类型 |
| 126 | func (r *PIIRedactor) AddCustomPIIType(piiType PIIType, replacement string) { |