Documentation
¶
Index ¶
- func GetStringRes(g *Generator, sep string) (string, error)
- func ScopeGet[T any](st ScopeType, what string) (T, error)
- type CommandMeta
- type CommandType
- type EventInput
- type EventType
- type Events
- func (e *Events) CallEvents(input *EventInput, name string, canWorkWithoutHandler bool) error
- func (e *Events) GetEvents(name string) ([]EventType, error)
- func (e *Events) NewEvent(name string, event EventType)
- func (e *Events) NewEventBefore(name string, event EventType) error
- func (e *Events) Scope() ScopeType
- type EventsInterface
- type Generator
- type Logger
- type Option
- type ScopeType
- type UniversalEngineParams
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CommandMeta ¶
type CommandMeta[E, N any] struct { Handler CommandType[E, N] Doc string }
type CommandType ¶
type EventInput ¶ added in v1.3.5
type EventInput struct {
Option *Option
Input interface{}
}
type EventType ¶
type EventType func(*Events, *EventInput) error
type Events ¶
Events manages an ordered collection of event handlers. Each event has a name (string) and a list of EventType functions. The CallEvents method invokes all handlers of an event in registration order. Events can also automatically wrap calls with start/end events for logging.
func NewEvents ¶
NewEvents creates an empty Events instance with an ordered map. The Scope map is initially empty but can be used to pass data between event handlers.
func (*Events) CallEvents ¶
func (e *Events) CallEvents(input *EventInput, name string, canWorkWithoutHandler bool) error
func (*Events) NewEventBefore ¶ added in v1.2.0
type EventsInterface ¶ added in v1.3.5
type Generator ¶
type Generator struct {
Pipeline []string
// contains filtered or unexported fields
}
Generator accumulates code fragments (strings or bytes) into named points (e.g., "pre", "main"). The Pipeline defines the order in which points are emitted. It supports both text and binary generation modes via res_type. Thread‑safe due to internal mutex.
func NewGenerator ¶
NewGenerator initializes a Generator with a given resource type (StringResType or ByteResType) and a pipeline slice. Empty code slices are pre‑created for each pipeline point.
func (*Generator) GetBytesRes ¶
func (*Generator) GetStringArrRes ¶
type Logger ¶
type Logger struct {
Logging map[string]bool
Log []string
Statuses map[string]string
DefaultStatusForm string
// contains filtered or unexported fields
}
Logger is a thread-safe structured logger for engine diagnostics. It stores a list of log lines, supports custom status formats, and allows different formatting per status (e.g., "error", "info", "debug"). Typical usage: attach to UniversalEngineParams.Logger.
func NewLogger ¶
NewLogger creates a new Logger with an optional defaultStatusForm. The format uses three placeholders: %s for status, %v for timestamp, and %s for the message. Example default: "%s [%v] [%s]\n" If empty string is passed, the default format is used.
func (*Logger) GetLog ¶
GetLog returns the entire log as a single string with newline separators. It is useful for saving logs to a file or showing them after execution.
func (*Logger) GetStatusForm ¶
GetStatusForm returns the format string associated with the given status, falling back to DefaultStatusForm if no custom format is set. Custom formats can be registered by directly assigning to l.Statuses map.
func (*Logger) PrintLog ¶
PrintLog writes a log entry to stdout and appends it to the internal slice. The status string determines the format via GetStatusForm (if a custom format for that status exists). The message is inserted into the format. Example: logger.PrintLog("error", "failed to parse token")
type UniversalEngineParams ¶
type UniversalEngineParams struct {
// Generator *Generator - controls code/output generation across pipeline points.
Generator *Generator
// Event *Events - allows hooking into parsing and command dispatch.
Event EventsInterface
// Scope ScopeType - a map[string]interface{} that can be used to share
// variables between events, parsers, and command handlers.
Scope ScopeType
// Logger *Logger - if set, logs internal steps (event calls, errors).
Logger *Logger
Context context.Context
}
UniversalEngineParams is a container shared by both StringEngine and ByteEngine. It holds the Generator (for output accumulation), Events (for hooks), Scope (for passing arbitrary data between stages), and Logger (for diagnostics). This struct is embedded (not composed by pointer) in the engine types, promoting its fields and methods to the engine itself.
func NewUniversalEngineParams ¶
func NewUniversalEngineParams( generator *Generator, events *Events, scope ScopeType, logger *Logger, context context.Context, ) (*UniversalEngineParams, error)
NewUniversalEngineParams constructs an initialized UniversalEngineParams. It automatically injects two event handlers into the Events system:
- CallEventsStartEvent - logs the start of any event call (debug level)
- CallEventsEndEvent - logs the end, including any error
Parameters: generator, events, scope, logger. All must be non‑nil. Returns a filled struct or an error if event registration fails.
func (*UniversalEngineParams) GetContext ¶
func (p *UniversalEngineParams) GetContext() context.Context