driver

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DummyModem = &GeneralModem[Processor]{
	Marshaler:   func(any) ([]byte, error) { return nil, nil },
	Unmarshaler: func([]byte, any) error { return nil },
}
View Source
var (
	// ErrSerializeNotSupport not support serialize error
	ErrSerializeNotSupport = errors.New("Processor not support serialize")
)
View Source
var SlashPathParser = new(DelimiterPathParser).WithDelimiter("/")

SlashPathParser slash path parser equal to DelimiterPathParser{delimiter: "/"}

Functions

This section is empty.

Types

type CURLProcessor

type CURLProcessor struct {
	// P is the target path of the Processor
	P string `json:"path,omitempty"`

	// URL the target url
	URL string `json:"url"`
	// Method the method to call URL
	Method string `json:"method,omitempty"`
	// Body post with data
	Body   []byte              `json:"body,omitempty"`
	Header map[string][]string `json:"header,omitempty"`

	// A is the author of the Processor
	A string `json:"author"`
	// C is the create time of the Processor
	C time.Time `json:"created_at"`
}

CURLProcessor

func (*CURLProcessor) Author

func (op *CURLProcessor) Author() string

func (*CURLProcessor) CreatedAt

func (op *CURLProcessor) CreatedAt() time.Time

func (*CURLProcessor) Load

func (op *CURLProcessor) Load(data []byte) error

func (*CURLProcessor) Path

func (op *CURLProcessor) Path() string

func (*CURLProcessor) Process

func (op *CURLProcessor) Process(rc *RealizeContext, _ []byte) ([]byte, error)

func (*CURLProcessor) Save

func (op *CURLProcessor) Save() []byte

func (*CURLProcessor) Type

func (op *CURLProcessor) Type() string

type CombinedProcessor

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

CombinedProcessor chains multiple processors into a single one. Processors are applied sequentially: each one's output becomes the next one's input.

func CombineProcessor

func CombineProcessor(procs ...Processor) *CombinedProcessor

CombineProcessor creates a processor that chains the given processors sequentially.

func (*CombinedProcessor) Author

func (c *CombinedProcessor) Author() string

func (*CombinedProcessor) CreatedAt

func (c *CombinedProcessor) CreatedAt() time.Time

func (*CombinedProcessor) Load

func (c *CombinedProcessor) Load([]byte) error

func (*CombinedProcessor) Path

func (c *CombinedProcessor) Path() string

func (*CombinedProcessor) Process

func (c *CombinedProcessor) Process(rc *RealizeContext, before []byte) ([]byte, error)

func (*CombinedProcessor) Save

func (c *CombinedProcessor) Save() []byte

func (*CombinedProcessor) Type

func (c *CombinedProcessor) Type() string

type DelimiterPathParser

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

DelimiterPathParser delimiter path parser

func (*DelimiterPathParser) AppendPath

func (d *DelimiterPathParser) AppendPath(path, name string) string

func (*DelimiterPathParser) GetLevel

func (d *DelimiterPathParser) GetLevel(path string) int

func (*DelimiterPathParser) GetNameByLevel

func (d *DelimiterPathParser) GetNameByLevel(path string, level int) string

func (DelimiterPathParser) WithDelimiter

func (d DelimiterPathParser) WithDelimiter(delimiter string) *DelimiterPathParser

type Driver

type Driver interface {
	Name() string

	PathParser
	Realizer
	Modem
}

Driver driver interface

type DummyDriver

type DummyDriver struct {
	PathParser
	Realizer
	Modem
}

DummyDriver return a dummy driver

func NewDummyDriver

func NewDummyDriver() *DummyDriver

NewDummyDriver ...

func (DummyDriver) Name

func (DummyDriver) Name() string

type DummyProcessor

type DummyProcessor struct{}

func (*DummyProcessor) Author

func (op *DummyProcessor) Author() string

func (*DummyProcessor) CreatedAt

func (op *DummyProcessor) CreatedAt() time.Time

func (*DummyProcessor) Load

func (op *DummyProcessor) Load([]byte) error

func (*DummyProcessor) Path

func (op *DummyProcessor) Path() string

func (*DummyProcessor) Process

func (op *DummyProcessor) Process(_ *RealizeContext, before []byte) (after []byte, err error)

func (*DummyProcessor) Save

func (op *DummyProcessor) Save() []byte

func (*DummyProcessor) Type

func (op *DummyProcessor) Type() string

type GeneralModem

type GeneralModem[T Processor] struct {
	Marshaler   func(in any) (out []byte, err error)
	Unmarshaler func(data []byte, v any) error
}

GeneralModem json moden

func (*GeneralModem[T]) Marshal

func (m *GeneralModem[T]) Marshal(ops ...Processor) ([]byte, error)

func (*GeneralModem[T]) Unmarshal

func (m *GeneralModem[T]) Unmarshal(data []byte) ([]Processor, error)

type JSONDriver

type JSONDriver struct {
	PathParser
	Realizer
	Modem
}

JSONDriver is a driver for JSON type rule tree

func NewJSONDriver

func NewJSONDriver() *JSONDriver

NewJSONDriver create a new json driver

func (JSONDriver) Name

func (JSONDriver) Name() string

Name return driver name

type JSONProcessor

type JSONProcessor struct {
	// P is the target path of the Processor
	P string `json:"path"`

	// T is the type of the Processor
	T string `json:"type"`
	// JSONPath is the json path of the Processor
	JSONPath string `json:"json_path"`
	// V is the value of the Processor
	V []byte `json:"value"`

	// A is the author of the Processor
	A string `json:"author"`
	// C is the create time of the Processor
	C time.Time `json:"created_at"`
}

JSONProcessor is a Processor for JSON type rule tree

func (*JSONProcessor) Author

func (op *JSONProcessor) Author() string

func (*JSONProcessor) CreatedAt

func (op *JSONProcessor) CreatedAt() time.Time

func (*JSONProcessor) Load

func (op *JSONProcessor) Load(data []byte) error

func (*JSONProcessor) Path

func (op *JSONProcessor) Path() string

func (*JSONProcessor) Process

func (op *JSONProcessor) Process(_ *RealizeContext, before []byte) (after []byte, err error)

func (*JSONProcessor) Save

func (op *JSONProcessor) Save() []byte

func (*JSONProcessor) Type

func (op *JSONProcessor) Type() string

type Modem

type Modem interface {
	// ProcessorsForSave get Processors data for save
	Marshal(...Processor) ([]byte, error)

	// LoadProcessors load Processors from data
	Unmarshal(data []byte) ([]Processor, error)
}

Modem Processors modem

type PathParser

type PathParser interface {
	// GetLevel get level from path
	GetLevel(path string) (level int)
	// GetNameByLevel get node name from path by level
	// return empty string if level is out of range
	GetNameByLevel(path string, level int) (name string)
	// AppendPath append path
	AppendPath(path, name string) (newPath string)
}

PathParser path parser

type Processor

type Processor interface {
	// Path return target tree path, not necessary
	Path() string

	// Type return processor type
	Type() string
	// Process do process rule
	Process(rc *RealizeContext, before []byte) (after []byte, err error)

	// informatin
	Author() string
	CreatedAt() time.Time

	// Load load Processor from data
	Load([]byte) error
	// Save ...
	Save() []byte
}

Processor rule processor

type RawProcessor

type RawProcessor struct {
	Proc func(ctx *RealizeContext, before []byte) (after []byte, err error)
	// contains filtered or unexported fields
}

func (*RawProcessor) Author

func (op *RawProcessor) Author() string

func (*RawProcessor) CreatedAt

func (op *RawProcessor) CreatedAt() time.Time

func (*RawProcessor) Load

func (op *RawProcessor) Load(data []byte) error

func (*RawProcessor) Path

func (op *RawProcessor) Path() string

func (*RawProcessor) Process

func (op *RawProcessor) Process(ctx *RealizeContext, before []byte) (after []byte, err error)

func (*RawProcessor) Save

func (op *RawProcessor) Save() []byte

func (*RawProcessor) Type

func (op *RawProcessor) Type() string

type RealizeContext

type RealizeContext struct {
	context.Context
	// TreePath is the path of the current tree node being processed.
	TreePath string
	// Params holds key-value pairs from the request, for template interpolation etc.
	Params map[string]string
	// ParentContent holds the realized content of the parent node.
	ParentContent []byte
}

RealizeContext carries runtime information for dynamic rule construction.

type Realizer

type Realizer interface {
	// Realize realize rule
	Realize(rc *RealizeContext, rule []byte, ops ...Processor) ([]byte, error)
}

Realizer realize rule

type StdRealizer

type StdRealizer struct{}

StdRealizer standard rule driver

func (*StdRealizer) Realize

func (r *StdRealizer) Realize(rc *RealizeContext, rule []byte, procs ...Processor) ([]byte, error)

Realizer calculate rule

type TOMLDriver

type TOMLDriver struct {
	PathParser
	Realizer
	Modem
}

TOMLDriver is a driver for TOML type rule tree

func NewTOMLDriver

func NewTOMLDriver() *TOMLDriver

NewTOMLDriver create a new toml driver

func (TOMLDriver) Name

func (TOMLDriver) Name() string

Name return driver name

type TOMLProcessor

type TOMLProcessor struct {
	// P is the target path of the Processor
	P string `json:"path"`

	// T is the type of the Processor
	T string `json:"type"`
	// TOMLPath is the toml key path of the Processor (dot-separated)
	TOMLPath string `json:"toml_path"`
	// V is the value of the Processor
	V []byte `json:"value"`

	// A is the author of the Processor
	A string `json:"author"`
	// C is the create time of the Processor
	C time.Time `json:"created_at"`
}

TOMLProcessor is a Processor for TOML type rule tree

func (*TOMLProcessor) Author

func (op *TOMLProcessor) Author() string

func (*TOMLProcessor) CreatedAt

func (op *TOMLProcessor) CreatedAt() time.Time

func (*TOMLProcessor) Load

func (op *TOMLProcessor) Load(data []byte) error

func (*TOMLProcessor) Path

func (op *TOMLProcessor) Path() string

func (*TOMLProcessor) Process

func (op *TOMLProcessor) Process(_ *RealizeContext, before []byte) (after []byte, err error)

func (*TOMLProcessor) Save

func (op *TOMLProcessor) Save() []byte

func (*TOMLProcessor) Type

func (op *TOMLProcessor) Type() string

type TileDriver

type TileDriver struct {
	PathParser
	Realizer
	Modem
}

TileDriver is a driver for raw type rule tree

func NewTileDriver

func NewTileDriver() *TileDriver

func (TileDriver) Name

func (TileDriver) Name() string

type XMLDriver

type XMLDriver struct {
	PathParser
	Realizer
	Modem
}

XMLDriver is a driver for XML type rule tree

func NewXMLDriver

func NewXMLDriver() *XMLDriver

NewXMLDriver create a new xml driver

func (XMLDriver) Name

func (XMLDriver) Name() string

Name return driver name

type XMLProcessor

type XMLProcessor struct {
	// P is the target path of the Processor
	P string `json:"path"`

	// T is the type of the Processor
	T string `json:"type"`
	// XMLPath is the xml element path of the Processor (slash-separated)
	XMLPath string `json:"xml_path"`
	// V is the value of the Processor
	V []byte `json:"value"`

	// A is the author of the Processor
	A string `json:"author"`
	// C is the create time of the Processor
	C time.Time `json:"created_at"`
}

XMLProcessor is a Processor for XML type rule tree

func (*XMLProcessor) Author

func (op *XMLProcessor) Author() string

func (*XMLProcessor) CreatedAt

func (op *XMLProcessor) CreatedAt() time.Time

func (*XMLProcessor) Load

func (op *XMLProcessor) Load(data []byte) error

func (*XMLProcessor) Path

func (op *XMLProcessor) Path() string

func (*XMLProcessor) Process

func (op *XMLProcessor) Process(_ *RealizeContext, before []byte) (after []byte, err error)

func (*XMLProcessor) Save

func (op *XMLProcessor) Save() []byte

func (*XMLProcessor) Type

func (op *XMLProcessor) Type() string

type YAMLDriver

type YAMLDriver struct {
	PathParser
	Realizer
	Modem
}

YAMLDriver is a driver for YAML type rule tree

func NewYAMLDriver

func NewYAMLDriver() *YAMLDriver

func (YAMLDriver) Name

func (YAMLDriver) Name() string

type YAMLProcessor

type YAMLProcessor struct {
	T string `json:"type"`
	V []byte `json:"value"`
}

func (*YAMLProcessor) Author

func (op *YAMLProcessor) Author() string

func (*YAMLProcessor) CreatedAt

func (op *YAMLProcessor) CreatedAt() time.Time

func (*YAMLProcessor) Load

func (op *YAMLProcessor) Load(data []byte) error

func (*YAMLProcessor) Path

func (op *YAMLProcessor) Path() string

func (*YAMLProcessor) Process

func (op *YAMLProcessor) Process(_ *RealizeContext, before []byte) (after []byte, err error)

func (*YAMLProcessor) Save

func (op *YAMLProcessor) Save() []byte

func (*YAMLProcessor) Type

func (op *YAMLProcessor) Type() string

Jump to

Keyboard shortcuts

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