A Go library for removing personally identifiable information (PII) from text data.
This project follows standard Go package conventions:
deidentify/
├── doc.go # Package documentation
├── deidentify.go # Main package implementation
├── data.go # Replacement value tables (names, domains, streets)
├── patterns.go # Regular expressions used for PII detection
├── deidentify_test.go # Package tests
├── example_test.go # Runnable godoc examples
├── benchmark_test.go # Performance benchmarks
├── examples/ # Example programs
│ ├── basic/ # Simple text deidentification
│ ├── table/ # Table-based deidentification
│ ├── slices/ # CSV-like [][]string deidentification
│ └── international/ # International address handling
└── go.mod # Module definition
The package provides functions to detect and redact PII from text. It can be imported and used in your Go applications:
import "github.com/aliengiraffe/deidentify"See the examples directory for detailed usage patterns.
This package follows Go's design philosophy:
- Simplicity: The API is designed to be simple and intuitive
- Composability: Functions can be combined to create custom deidentification pipelines
- Efficiency: Optimized for performance with minimal allocations
- Error handling: Uses Go's standard error patterns for robust error reporting
The package exposes types and functions following Go's idiomatic practices:
Deidentifier: Replaces PII with deterministic, format-preserving substitutes. Safe for concurrent use.DataType: The kind of PII a value holds (TypeName,TypeEmail,TypePhone,TypeSSN,TypeCreditCard,TypeAddress,TypeGeneric)Table/Column: Column-oriented data to deidentify as a unit
GenerateSecretKey() (string, error): Returns a hex-encoded 256-bit random keyNewDeidentifier(secretKey string) *Deidentifier: Creates a deidentifier bound to a secret key
Text(text string) (string, error): Finds and replaces PII in free-form textTable(table *Table) (*Table, error): Deidentifies column-oriented data by declared typeSlices(data [][]string, optional ...interface{}) ([][]string, error): Deidentifies CSV-like data, inferring column types when not supplied
Name, Email, Phone, SSN, CreditCard, and Address each deidentify one
value of a known type, returning (string, error). ClearMappings() discards
the accumulated mapping tables.
Replacements are deterministic: the same input and secret key always produce the same output, which preserves referential integrity across records and runs.
When contributing to this project, follow these practices:
-
Use
gofmtto format all code -
Write tests for all new functionality
-
Follow Effective Go guidelines:
- Meaningful variable names
- Proper error handling with descriptive error messages
- Concise documentation with examples
- Implementation of standard interfaces where appropriate
-
Use idiomatic Go patterns:
- Return errors rather than using
panic - Use composition over inheritance
- Make zero values useful
- Return errors rather than using
Run the test suite with:
go test
For more verbose output:
go test -v
The library includes multiple examples to demonstrate different usage patterns:
Simple text deidentification of strings and specific PII types:
go run examples/basic/main.go
Comprehensive example for deidentifying structured data in tables:
go run examples/table/main.go
[License details here]