masker

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 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

func WithDebugMode added in v1.0.4

func WithDebugMode() option

func WithFixedMaskString added in v1.0.4

func WithFixedMaskString(maskStr string) option

func WithMaskFunc added in v1.0.4

func WithMaskFunc(maskFunc func(field any) string) option

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