https://github.com/hisdream86/go-anonymizer
Simple anonymizer for any structured data
https://github.com/hisdream86/go-anonymizer
anonymization deidentification go
Last synced: 2 months ago
JSON representation
Simple anonymizer for any structured data
- Host: GitHub
- URL: https://github.com/hisdream86/go-anonymizer
- Owner: hisdream86
- License: mit
- Created: 2019-11-27T07:41:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-15T03:09:28.000Z (over 5 years ago)
- Last Synced: 2025-01-17T20:41:02.385Z (4 months ago)
- Topics: anonymization, deidentification, go
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Anonymizer
Simple anonymization tool for de-identifying your structurized data. You can easily anonymize your data with *Struct Tag* `anonymize:"{replacer}"`.*Note: only string values are supported*
# Installation
$ go get github.com/hisdream86/go-anonymizer# Example
```go
package mainimport (
"crypto/sha256"
"encoding/hex"
"fmt"anonymizer "github.com/hisdream86/go-anonymizer"
)type Example struct {
// Anonymize with asterisk (*)
MaskedField string `anonymize:"asterisk"`
// Anonymize to empty string ("")
EmptyField string `anonymize:"empty"`
// Anonymize with custom handler
CustomField string `anonymize:"mysha256"`
// Anoymize nested Field
NestedField struct {
MaskedField string `anonymize:"asterisk"`
}
// Anonymize array Field
ArrayField []string `anonymize:"asterisk"`
// Don't anonymize
PlainField string
}type NestedField struct {
MaskedField string `anonymize:"asterisk"`
}func main() {
var target = Example{
MaskedField: "MaskedField",
EmptyField: "EmptystringField",
CustomField: "CustomField",
PlainField: "PlainField",
NestedField: NestedField{
MaskedField: "NestedMaskedField",
},
ArrayField: []string{"Field 1", "Field 2"},
}// Register custom replacer for anonymizing data with SHA256 hashing
anonymizer.AddCustomReplacer("mysha256", func(source string) string {
h := sha256.New()
h.Write([]byte(source))
return hex.EncodeToString(h.Sum(nil))
})if err := anonymizer.Anonymize(&target); err != nil {
fmt.Println("Fail to anonymize target data.")
}fmt.Println(target)
}
```# Replacers
## Default Replacers
Go Anonymizer provides following default replacers.### asterisk
Replace your data with multiple asterisks `*`. The number of asterisk character is same with your string's length.> "Hello World" -> "***********"
### empty
Replace your data with empty string.> "Hello World" -> ""
## Custom Replacers
If you want to use your custom replacer, you can use `AddCustomReplacer()` and `RemoveCustomReplacer()`.