base

package
v0.0.0-...-e482363 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Router  = "router"
	Literal = "literal"
	Mode    = "mode"
	This    = "this"
	Array   = "array"
)

Variables

This section is empty.

Functions

func DeepEqual

func DeepEqual(v1, v2 any) bool

DeepEqual reports whether x and y are “deeply equal,” defined as follows. []any: len of []any is equal, values in same position are deeply equal map[string]any: len of map[string]any is equal, values with same key are deeply equal others: return the result of ==

func Rest

func Rest[T any](s []T) []T

Rest return rest of slices

Types

type GetterPlugin

type GetterPlugin interface {
	Exec(s *Setter, root, data any, expression []string, param []any) any
	Verify(param []any) ([]any, error)
	Name() string
}

GetterPlugin execute when a router string is equal to result of Name()

type Setter

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

Setter provide method 'set' and 'get'

func (*Setter) Get

func (s *Setter) Get(root, data, expression any) any

Get get value data by expression

func (*Setter) GetByRouter

func (s *Setter) GetByRouter(root any, data any, routers []string, param []any) any

GetByRouter get value by routers and param.

func (*Setter) GetBySlice

func (s *Setter) GetBySlice(root, data any, expressions []any) any

GetBySlice get value by expressions first element of expressions is declared as router. rest elements are declared as params.

func (*Setter) GetPluginName

func (s *Setter) GetPluginName(name string) string

GetPluginName return plugin name with prefix

func (*Setter) GetSegmentation

func (s *Setter) GetSegmentation() string

GetSegmentation return segmentation

func (*Setter) Set

func (s *Setter) Set(src any, dst any, phases []map[string]any) (any, map[string]any)

Set dst by phases and data of src. Return new value of dst and info of plugins return. The origin dst may be changed. The correct way to use it is -- dst,info = s.Set(src,dst,phases)

func (*Setter) SetByRouter

func (s *Setter) SetByRouter(dst any, router []string, data any) any

SetByRouter set value of dst by router and data of src

func (*Setter) SetDefaultPhases

func (s *Setter) SetDefaultPhases(phases []map[string]any)

SetDefaultPhases defaultPhases is used in Set when phases is nil

func (*Setter) SetForArray

func (s *Setter) SetForArray(forArray bool)

SetForArray traverse array to get value by rest of routers when meet an array in GetByRouter.

Logic of forArray is as same as plugin 'for'. Set forArray to true allowed you to omit router 'for' in routers. On the other hand it makes the mean of router ambiguous.

func (*Setter) SetGetterPlugins

func (s *Setter) SetGetterPlugins(plugins []GetterPlugin)

SetGetterPlugins set getter plugins of setter

func (*Setter) SetOmitempty

func (s *Setter) SetOmitempty(omitempty bool)

SetOmitempty delete null value in map[string]any if omitempty is true

func (*Setter) SetPluginPrefix

func (s *Setter) SetPluginPrefix(prefix string)

SetPluginPrefix plugin prefix is a string to mark a router string is a pointer to a plugin. Works in both setter and getter.

func (*Setter) SetRedirectSrc

func (s *Setter) SetRedirectSrc(redirectSrc bool)

SetRedirectSrc set src to dst while a phase finished in Set

func (*Setter) SetSegmentation

func (s *Setter) SetSegmentation(segmentation string)

SetSegmentation segmentation is a string to split routers. Works in both setter and getter.

func (*Setter) SetSetterPlugins

func (s *Setter) SetSetterPlugins(plugins []SetterPlugin)

SetSetterPlugins set setter plugins of setter

func (*Setter) Verify

func (s *Setter) Verify(phases []map[string]any) error

Verify return error when phases expression is valid use defaultPhases when phases is nil.

type SetterPlugin

type SetterPlugin interface {
	Exec(s *Setter, src, dst any, phase map[string]any) (any, map[string]any)
	Verify(phase map[string]any) error
	Name() string
}

SetterPlugin execute when value of field 'mode' of phase is equal to result of Name()

Jump to

Keyboard shortcuts

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