https://github.com/wils0ns/redact
Redactor for JSON and text
https://github.com/wils0ns/redact
blackout censor golang json omit redact string text
Last synced: 7 months ago
JSON representation
Redactor for JSON and text
- Host: GitHub
- URL: https://github.com/wils0ns/redact
- Owner: wils0ns
- License: mit
- Created: 2020-08-29T11:23:52.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-01T23:43:25.000Z (about 5 years ago)
- Last Synced: 2025-01-26T12:41:35.569Z (8 months ago)
- Topics: blackout, censor, golang, json, omit, redact, string, text
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Redact
[](http://godoc.org/github.com/wils0ns/redact)
[](https://goreportcard.com/report/github.com/wils0ns/redact)
[](https://codecov.io/gh/wils0ns/redact)JSON and text redactor.
## Blackout secrets in a text
Code:
```go
s = NewSecret(`[0-9]{3}\.[0-9]{3}\.[0-9]{3}-[0-9]{2}`, BlackOut, []byte("█"))
```Original text:
```text
These are a couple of CPFs: 321.654.987-00 and 789.456.123-00
```Redacted text:
```text
These are a couple of CPFs: ██████████████ and ██████████████
```## Blackout secret values and omit secret fields from JSON
Code:
```go
bo := []byte("█")
inq := New()
inq.AddSecretValue(NewSecret("secret[s]?", BlackOut, bo))
inq.AddSecretValue(NewSecret("SSN", BlackOut, []byte("")))
inq.AddSecretValue(NewSecret(`[1-9]{3}-[1-9]{2}-[1-9]{4}`, BlackOut, bo))inq.AddSecretField("date")
inq.AddSecretField("^SSN$")
```Original JSON:
```json
{
"Name":"Wilson",
"create_date": "2020-08-31 15:51:14+00:00",
"modify_date": "2020-08-31 15:52:15+00:00",
"SSN": "123-45-6789",
"quote": "We all have secrets"
}
```Redacted JSON:
```json
{
"Name":"Wilson",
"quote":"We all have ███████"
}
```Check out the full [code examples](example_test.go).