core

package
v0.0.0-...-1ba7408 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Comparison

type Comparison map[string]interface{}

yeah, comparisons are just big maps, in the end...

func CompareFiles

func CompareFiles(filepathOne, filepathTwo string, options *ComparisonOptions, doLog bool) (Comparison, error)

CompareFiles : getting a diff between 2 files, JSON or XML (for now)

func CompareFolders

func CompareFolders(pathOne, pathTwo string, options *ComparisonOptions) (Comparison, error)

CompareFolders : getting a diff between 2 files, JSON or XML (for now)

type ComparisonOptions

type ComparisonOptions struct {
	FileType       FileType                 // the type of the files we're comparing
	IdParamsString string                   // a JSON representation of a IdentificationParameter parameter; can be the path to an existing JSON file
	IdParams       *IdentificationParameter // the properties (values of the map) serving as unique IDs for given paths (keys of the map)
	Check          bool                     // if true, then the ID params are output to allow for some checks
	Fast           bool                     // if true, then, in an array, an object's index is used as its IDProp, if none is specified for its path in the data tree; i.e. the IDProp `#index` is used, instead of nothing
	Silent         bool                     // if true, then no info / warning message is written out
	StopAtFirst    bool                     // if true, then, when comparing folders, we stop at the first couple of files that differ
	Logger         Logger                   // a logger
	IgnoredString  string                   // the files to ignore, separated by a comma
	Ignored        map[string]bool          // the ignored files
	AllowRaw       bool                     // if true, then it's allowed to display the raw JSON entities as difference, when added or removed; else, a display template is required
	IsXml          bool                     // if true, then the compared files are XML files
	NParallel      int                      // the number of routines used at the same time when comparing several files at once (i.e. comparing folders)
}

func (*ComparisonOptions) GetFileType

func (thisComp *ComparisonOptions) GetFileType() FileType

func (*ComparisonOptions) GetIdParams

func (thisComp *ComparisonOptions) GetIdParams() *IdentificationParameter

func (*ComparisonOptions) Resolve

func (thisComp *ComparisonOptions) Resolve()

Resolve allows to transform some of the options, so as to make them usable by the comparison functions

func (*ComparisonOptions) SetDefaultLogger

func (thisComp *ComparisonOptions) SetDefaultLogger() *ComparisonOptions

func (*ComparisonOptions) SetLogger

func (thisComp *ComparisonOptions) SetLogger(logger Logger) *ComparisonOptions

type ConditionalIDParameter

type ConditionalIDParameter struct {
	Prop string `json:"prop,omitempty"`
	Is   string `json:"is,omitempty"`
	IdentificationParameter
}

ConditionalIDParameter is an IdentificationParameter that applies only if a given prop has the designated value

type FileType

type FileType string

the types for the files we're comparing

const (
	FileTypeJSON FileType = "JSON"
	FileTypeXML  FileType = "XML"
)

type IdentificationParameter

type IdentificationParameter struct {
	At       string                              `json:"at,omitempty"`   // the relative path at which to use this identification parameter
	Use      []string                            `json:"_use,omitempty"` // which simple properties to concatenate to form a key
	Tpl1     []string                            `json:"tpl1,omitempty"` // a formattable string (Go template) to build an alias for an object, instead of outputting it completely in the comparison
	TplN     []string                            `json:"tplN,omitempty"` // a formattable string (Go template) to build an alias for an object, instead of outputting it completely in the comparison
	Incr     bool                                `json:"incr,omitempty"` // if true, then any key built with this ID param is augmented with a counter of its occurrences
	When     []*ConditionalIDParameter           `json:"when,omitempty"` // when to apply this identification parameter, and what to do (_use, look, or when ?)
	Look     []*IdentificationParameter          `json:"look,omitempty"` // which relationships to look into
	For      map[string]*IdentificationParameter `json:"_for,omitempty"` // how to deal with the embedded objects from this place
	Name     string                              `json:"name,omitempty"` // a name for this ID parameter, that may be used as a prefix for the keys built here
	FullPath string                              `json:"path,omitempty"` // the relative path at which to use this identification parameter
	Keep     bool                                `json:"keep,omitempty"` // if true, then, when comparing slice elements with this ID param, we're not clearing the identical elements before comparing the diverging ones
	// contains filtered or unexported fields
}

IdentificationParameter allows to recursively describe how to identity the entities within arrays in a data tree

func (*IdentificationParameter) BuildUniqueKey

func (thisParam *IdentificationParameter) BuildUniqueKey(ent *JsonEntity, currentPathValue string) (result string)

buildUniqueKey tries to build a unique key for the given object, according to what's configured on the given ID param

func (*IdentificationParameter) Resolve

func (thisParam *IdentificationParameter) Resolve(full bool) error

Resolve makes sure any identification parameter can be properly located within the root identification parameter; we take the opportunity here for checking this object's validity

type JsonEntity

type JsonEntity struct {
	// contains filtered or unexported fields
}

type Logger

type Logger interface {
	Info(str string, params ...interface{})
	Debug(str string, params ...interface{})
	Warn(str string, args ...interface{})
}

This logger interface does not allow to log errors, since we want errors to created as objects, and be returned to the callers

Jump to

Keyboard shortcuts

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