privacy

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateEmail

func ValidateEmail(email string) bool

ValidateEmail validates email address

func ValidateIDCard

func ValidateIDCard(id string) bool

ValidateIDCard validates Chinese ID card number

func ValidatePhone

func ValidatePhone(phone string) bool

ValidatePhone validates Chinese mobile phone number

Types

type AuditEntry

type AuditEntry struct {
	Original  string   `json:"original"`
	Detected  []string `json:"detected"` // Types of PII found
	Redacted  string   `json:"redacted"`
	Timestamp string   `json:"timestamp"`
}

AuditEntry represents a redaction audit log entry

type Config

type Config struct {
	Enabled        bool              `json:"enabled"`
	RedactPhone    bool              `json:"redact_phone"`
	RedactEmail    bool              `json:"redact_email"`
	RedactIDCard   bool              `json:"redact_id_card"`
	RedactBankCard bool              `json:"redact_bank_card"`
	RedactIP       bool              `json:"redact_ip"`
	RedactAddress  bool              `json:"redact_address"`
	CustomPatterns map[string]string `json:"custom_patterns"` // Name -> Regex
}

Config holds privacy configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default privacy configuration

type Match

type Match struct {
	Type  string
	Start int
	End   int
	Value string
}

Match represents a detected PII match

type Pattern

type Pattern struct {
	Name        string
	Regex       *regexp.Regexp
	Replacement string
}

Pattern represents a PII pattern

type Redactor

type Redactor struct {
	// contains filtered or unexported fields
}

Redactor handles PII detection and redaction

func DefaultRedactor

func DefaultRedactor() *Redactor

DefaultRedactor creates a redactor with default patterns

func NewRedactor

func NewRedactor(cfg *Config) *Redactor

NewRedactor creates a new redactor with the given configuration

func (*Redactor) AddPattern

func (r *Redactor) AddPattern(name, regex, replacement string)

AddPattern adds a custom PII pattern

func (*Redactor) ClearAuditLog

func (r *Redactor) ClearAuditLog()

ClearAuditLog clears the audit log

func (*Redactor) CountPII

func (r *Redactor) CountPII(text string) map[string]int

CountPII returns the count of PII items by type

func (*Redactor) Detect

func (r *Redactor) Detect(text string) []Match

Detect finds all PII in the text without replacing

func (*Redactor) Disable

func (r *Redactor) Disable()

Disable disables PII redaction

func (*Redactor) Enable

func (r *Redactor) Enable()

Enable enables PII redaction

func (*Redactor) GetAuditLog

func (r *Redactor) GetAuditLog() []AuditEntry

GetAuditLog returns the audit log

func (*Redactor) GetPatterns

func (r *Redactor) GetPatterns() []string

GetPatterns returns all configured patterns

func (*Redactor) IsEnabled

func (r *Redactor) IsEnabled() bool

IsEnabled returns whether redaction is enabled

func (*Redactor) Redact

func (r *Redactor) Redact(text string) string

Redact replaces all PII in the input text

func (*Redactor) RedactStruct

func (r *Redactor) RedactStruct(v interface{}) interface{}

RedactStruct recursively redacts all string fields in a struct

func (*Redactor) RedactWithContext

func (r *Redactor) RedactWithContext(text string) (string, []string)

RedactWithContext redacts PII and returns detected types

func (*Redactor) Restore

func (r *Redactor) Restore(text string, mapping map[string]string) string

Restore reverses redaction (for local processing only)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL