conversion

package
v1.59.8 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(moduleName string, conversion *Conversion) bool

Register adds Conversion implementation to Registry. Returns true to use with "var _ =".

func RegisterFunc

func RegisterFunc(moduleName string, srcVersion int, targetVersion int, conversionFunc ConversionFunc) bool

RegisterFunc adds a function as a Conversion to Registry. Returns true to use with "var _ =".

Types

type Chain

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

Chain is a chain of conversions for module.

func NewChain

func NewChain(moduleName string) *Chain

func NewNoConvChain

func NewNoConvChain(moduleName string) *Chain

NewNoConvChain return a chain with the latestVersion equal to 1 for modules without registered conversions.

func (*Chain) Add

func (c *Chain) Add(conversion *Conversion)

func (*Chain) Conversion

func (c *Chain) Conversion(srcVersion int) *Conversion

func (*Chain) ConvertToLatest

func (c *Chain) ConvertToLatest(fromVersion int, settings map[string]interface{}) (int, map[string]interface{}, error)

func (*Chain) Count

func (c *Chain) Count() int

Count returns a number of registered conversions for the module.

func (*Chain) IsKnownVersion

func (c *Chain) IsKnownVersion(version int) bool

IsKnownVersion returns whether version has registered conversion or the latest.

func (*Chain) LatestVersion

func (c *Chain) LatestVersion() int

func (*Chain) PreviousVersionsList

func (c *Chain) PreviousVersionsList() []int

PreviousVersionsList returns supported previous versions.

func (*Chain) VersionList

func (c *Chain) VersionList() []int

VersionList returns all valid versions (all previous and the latest).

type ConvRegistry

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

func Registry

func Registry() *ConvRegistry

func (*ConvRegistry) Add

func (r *ConvRegistry) Add(moduleName string, conversion *Conversion)

func (*ConvRegistry) Chain

func (r *ConvRegistry) Chain(moduleName string) *Chain

Chain returns a chain with registered conversions or a stub — a chain without conversions with version 1 as the latest.

type Conversion

type Conversion struct {
	Source     int
	Target     int
	Conversion ConversionFunc
}

func NewConversion

func NewConversion(srcVersion int, targetVersion int, conversionFunc ConversionFunc) *Conversion

func (*Conversion) Convert

func (c *Conversion) Convert(settings *Settings) (*Settings, error)

type ConversionFunc

type ConversionFunc func(settings *Settings) error

type Settings

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

Settings is a helper to simplify module settings manipulation in conversion functions. Access and update map[string]interface{} is difficult, so gjson and sjson come to the rescue.

func SettingsFromBytes

func SettingsFromBytes(bytes []byte) *Settings

func SettingsFromMap

func SettingsFromMap(in map[string]interface{}) (*Settings, error)

func SettingsFromString

func SettingsFromString(jsonStr string) *Settings

func SettingsFromYAML

func SettingsFromYAML(yamlStr string) (*Settings, error)

func (*Settings) Bytes

func (s *Settings) Bytes() []byte

Bytes returns underlying json text.

func (*Settings) Clear added in v1.45.0

func (s *Settings) Clear()

func (*Settings) Delete

func (s *Settings) Delete(path string) error

Delete removes field by path.

func (*Settings) DeleteAndClean

func (s *Settings) DeleteAndClean(path string) error

DeleteAndClean removes path and its empty parents. This method supports only dot separated paths. gjson's selectors and modifiers are not supported.

func (*Settings) DeleteIfEmptyParent

func (s *Settings) DeleteIfEmptyParent(path string) error

DeleteIfEmptyParent removes field by path if value is an empty object or an empty array.

func (*Settings) Get

func (s *Settings) Get(path string) gjson.Result

func (*Settings) IsEmptyNode

func (s *Settings) IsEmptyNode(path string) bool

IsEmptyNode returns true if value is empty array, or empty map.

func (*Settings) Map

func (s *Settings) Map() (map[string]interface{}, error)

Map transforms values into map[string]interface{} object.

func (*Settings) Set

func (s *Settings) Set(path string, value interface{}) error

func (*Settings) SetFromJSON

func (s *Settings) SetFromJSON(path string, jsonRawValue string) error

func (*Settings) String

func (s *Settings) String() string

Bytes returns underlying json text as string.

Jump to

Keyboard shortcuts

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