masker

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2024 License: MIT Imports: 4 Imported by: 0

README

json-masker

Opinionated Json masker package, allowing masking using json paths

GoDoc

How to use:

	jsonRaw := `{
		"name": "John Doe",
		"age": 30,
		"jobs": [{
			"id": 1,
			"name": "Software Engineer",
			"list": ["task1", "task2"]
		},
		{
			"id": 2,
			"name": "DevOps Engineer",
			"list": ["task1", "task2"]
		}]
	}`

	maskedPaths := []string{
		"$.name",
		"$.jobs[].name",
		"$.jobs[].list[]",
	}
	masker := masker.NewMasker(maskPaths, withFixedMaskString("[REDACTED]"), withDebugMode())
	masked, err := masker.Mask(jsonRaw, maskedPaths)
	if err != nil {
		panic(err)
	}
	println(masked)

    // Output:
    // {
    //     "age": 30,
    //     "name": "[REDACTED]",
    //     "jobs": [
    //         {
    //             "id": 1,
    //             "list": [
    //                 "[REDACTED]",
    //                 "[REDACTED]"
    //             ],
    //             "name": "[REDACTED]"
    //         },
    //         {
    //             "id": 2,
    //             "list": [
    //                 "[REDACTED]",
    //                 "[REDACTED]"
    //             ],
    //             "name": "[REDACTED]"
    //         }
    // }

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Masker

type Masker interface {
	Mask(data string, maskPaths []string) (string, error)
	// contains filtered or unexported methods
}

func NewMasker

func NewMasker(maskPaths []string, opts ...option) Masker

Jump to

Keyboard shortcuts

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