jsonnorm

package module
v0.0.0-...-5a5d2d4 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

jsonnorm

Go JSON normalization.

This module is helpful to test REST json services. It can modify JSON response to replace all time values in response to normalized view. For example replace time zone or set time to spefied one only for case when original value is in some period range from etalon.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Normalizer

type Normalizer struct {
	Rules []Rule
	Doc   string
}

func NewNormalizer

func NewNormalizer(doc string, rules ...Rule) *Normalizer

func (*Normalizer) AddRule

func (n *Normalizer) AddRule(r Rule) *Normalizer

func (*Normalizer) Apply

func (n *Normalizer) Apply() (string, error)

type Rule

type Rule interface {
	Paths() []string
	Apply(*ajson.Node) error
}

type TimeRule

type TimeRule struct {
	JSONPaths []string
	// If TZ is not nil, then we will normalize JSON timezone to TZ.
	TZ *time.Location
	// If JSONPath's specified time is in range from Time - PeriodBefore to
	// Time + PeriodAfter, then we will replace json value with Time.
	// If Time is zero, then we will not replace json value.
	Time         time.Time
	PeriodBefore time.Duration
	PeriodAfter  time.Duration
	// Time format layout. If not specified, then time.RFC3339
	Layout string
}

TimeRule specifies how to normalize json document. If we find nodes by jsonpath, we will replace

func (TimeRule) Apply

func (tr TimeRule) Apply(node *ajson.Node) error

func (TimeRule) Paths

func (tr TimeRule) Paths() []string

Jump to

Keyboard shortcuts

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