Documentation
ΒΆ
Overview ΒΆ
Package flow provides a high-performance, modular, and embeddable data pipeline orchestration and stream ETL library for Go. It allows developers to programmatically load, validate, and execute complex pipeline AST nodes (such as loops, parallel batches, and dynamic SQL/Go scripts) from XML configuration files.
Index ΒΆ
- func BuildClientAndRequest(elem HTTPClientElement) (*http.Client, *http.Request, error)
- func GetSchemaXSD() []byte
- func StreamETL(ctx context.Context, r *Registry, ...) (int64, error)
- func ValidateAST(preflightNodes []PipelineNode, flowNodes []PipelineNode, ...) error
- func ValidateXSD(xmlPath string, xsdPath string) error
- type AssertElement
- type DBHandle
- type DatabaseConfig
- type ETLOptions
- type ExcelReadElement
- type ExcelWriteElement
- type Executor
- type FileReadElement
- type FileSaveElement
- type HTTPClientElement
- type JsonPathElement
- type NodeKind
- type PipelineConfig
- type PipelineNode
- type Registry
- func (r *Registry) CloseDatabases()
- func (r *Registry) CopyVariables() map[string]interface{}
- func (r *Registry) GetDB(name string) (*sql.DB, error)
- func (r *Registry) GetDBHandle(name string) (DBHandle, error)
- func (r *Registry) GetVar(name string) interface{}
- func (r *Registry) GetVarBool(name string) bool
- func (r *Registry) GetVarFloat(name string) float64
- func (r *Registry) GetVarInt(name string) int
- func (r *Registry) GetVarString(name string) string
- func (r *Registry) GetVarTime(name string) time.Time
- func (r *Registry) InitDatabases(configs []DatabaseConfig) error
- func (r *Registry) InitVariables(configs []VariableConfig) error
- func (r *Registry) MergeVariables(src map[string]interface{})
- func (r *Registry) SetVar(name string, value interface{})
- func (r *Registry) Snapshot() *Registry
- type ScriptItem
- type ScriptResult
- type TemplateElement
- type VariableConfig
- type XmlXPathElement
- type YamlPathElement
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func BuildClientAndRequest ΒΆ added in v1.2.11
BuildClientAndRequest constructs fully configured http.Client and http.Request instances.
func GetSchemaXSD ΒΆ added in v1.1.0
func GetSchemaXSD() []byte
GetSchemaXSD returns the embedded XSD schema content as a byte slice.
func StreamETL ΒΆ
func StreamETL(ctx context.Context, r *Registry, srcDBName, queryStr, dstDBName, targetTable string, opts ETLOptions) (int64, error)
StreamETL streams query results line-by-line from a source database into a target database table.
func ValidateAST ΒΆ
func ValidateAST(preflightNodes []PipelineNode, flowNodes []PipelineNode, registeredDBs []DatabaseConfig) error
ValidateAST verifies script IDs, database names, and structural rules across preflight and flow ASTs.
func ValidateXSD ΒΆ
ValidateXSD invokes 'xmllint' to validate the XML file against the given XSD schema.
Types ΒΆ
type AssertElement ΒΆ added in v1.2.15
type AssertElement struct {
ID string `xml:"id,attr"`
Var string `xml:"var,attr"`
Equals string `xml:"equals,attr"`
Value string `xml:"value,attr"`
Operator string `xml:"operator,attr"`
Message string `xml:"message,attr"`
OnFailure string `xml:"on_failure,attr"` // "halt", "warn", "continue", "set_var"
FailVar string `xml:"fail_var,attr"`
FailVal string `xml:"fail_val,attr"`
FailureNodes []PipelineNode // Nodes inside <on_failure> block
}
type DBHandle ΒΆ
type DBHandle struct {
Conn *sql.DB // Connection pool handle
Driver string // Database driver name (e.g. "sqlite", "mysql")
}
DBHandle encapsulates an active sql.DB connection pool along with its driver name.
type DatabaseConfig ΒΆ
type DatabaseConfig struct {
Name string // Unique identifier for the database
Driver string // Database driver name (e.g. postgres, mysql, sqlite)
ConnectionString string // Driver-specific connection string
}
DatabaseConfig represents a database connection setup defined in the XML.
type ETLOptions ΒΆ added in v1.2.0
type ETLOptions struct {
BatchSize int // Number of rows per batch flush
Tablock bool // Acquire table lock for minimal logging on SQL Server
CheckConstraints bool // Enforce target constraints during MSSQL bulk insert
FireTriggers bool // Execute target table triggers during MSSQL bulk insert
KeepNulls bool // Preserve explicit NULL values during MSSQL bulk insert
}
ETLOptions encapsulates batching and engine-specific performance tuning flags.
type ExcelReadElement ΒΆ added in v1.2.13
type ExcelReadElement struct {
ID string `xml:"id,attr"`
File string `xml:"file,attr"`
Sheet string `xml:"sheet,attr"`
Header *bool `xml:"header,attr"`
Var string `xml:"var,attr"`
OutputVar string `xml:"output_var,attr"`
}
func (*ExcelReadElement) GetOutputVar ΒΆ added in v1.2.13
func (e *ExcelReadElement) GetOutputVar() string
type ExcelWriteElement ΒΆ added in v1.2.13
type Executor ΒΆ
type Executor struct {
// contains filtered or unexported fields
}
Executor orchestrates recursive pipeline AST node executions.
func NewExecutor ΒΆ
NewExecutor creates and returns a new Executor configured with the provided Registry.
func (*Executor) Execute ΒΆ
func (e *Executor) Execute(ctx context.Context, nodes []PipelineNode) ([]ScriptResult, error)
Execute triggers sequential or parallel tree evaluation for a slice of PipelineNodes.
func (*Executor) SetInterpHook ΒΆ added in v1.2.4
SetInterpHook registers a callback to customize Yaegi interpreter options.
func (*Executor) SetVerbose ΒΆ added in v1.1.0
SetVerbose sets whether execution start and finish events should be printed to the console.
type FileReadElement ΒΆ added in v1.2.13
type FileReadElement struct {
ID string `xml:"id,attr"`
File string `xml:"file,attr"`
Path string `xml:"path,attr"`
Filename string `xml:"filename,attr"`
Var string `xml:"var,attr"`
Variable string `xml:"variable,attr"`
OutputVar string `xml:"output_var,attr"`
OutputVariable string `xml:"output_variable,attr"`
OutVar string `xml:"out_var,attr"`
}
func (*FileReadElement) GetFilePath ΒΆ added in v1.2.13
func (f *FileReadElement) GetFilePath() string
func (*FileReadElement) GetOutputVar ΒΆ added in v1.2.13
func (f *FileReadElement) GetOutputVar() string
type FileSaveElement ΒΆ added in v1.2.13
type FileSaveElement struct {
ID string `xml:"id,attr"`
File string `xml:"file,attr"`
Path string `xml:"path,attr"`
Filename string `xml:"filename,attr"`
Var string `xml:"var,attr"`
Variable string `xml:"variable,attr"`
Append *bool `xml:"append,attr"`
Content string `xml:",chardata"`
}
func (*FileSaveElement) GetFilePath ΒΆ added in v1.2.13
func (f *FileSaveElement) GetFilePath() string
func (*FileSaveElement) GetInputVar ΒΆ added in v1.2.13
func (f *FileSaveElement) GetInputVar() string
type HTTPClientElement ΒΆ added in v1.2.11
type HTTPClientElement struct {
XMLName xml.Name `xml:"-"`
// Core Request Attributes
ID string `xml:"id,attr"`
URI string `xml:"uri,attr"`
URL string `xml:"url,attr"`
Method string `xml:"method,attr"`
Data string `xml:"data,attr"`
BodyContent string `xml:",chardata"`
Headers string `xml:"headers,attr"`
ContentType string `xml:"content_type,attr"`
// Variable Output Assignments
Var string `xml:"var,attr"`
Variable string `xml:"variable,attr"`
OutputVar string `xml:"output_var,attr"`
OutputVariable string `xml:"output_variable,attr"`
OutVar string `xml:"out_var,attr"`
StatusCodeVar string `xml:"status_code_var,attr"`
StatusCodeVariable string `xml:"status_code_variable,attr"`
StatusVar string `xml:"status_var,attr"`
StatusVariable string `xml:"status_variable,attr"`
// http.Client Attributes
Timeout string `xml:"timeout,attr"`
MaxRedirects *int `xml:"max_redirects,attr"`
FollowRedirects *bool `xml:"follow_redirects,attr"`
CookieJar *bool `xml:"cookie_jar,attr"`
// http.Transport Attributes
Proxy string `xml:"proxy,attr"`
TLSInsecureSkipVerify *bool `xml:"tls_insecure_skip_verify,attr"`
TLSHandshakeTimeout string `xml:"tls_handshake_timeout,attr"`
TLSServerName string `xml:"tls_server_name,attr"`
TLSMinVersion string `xml:"tls_min_version,attr"`
TLSMaxVersion string `xml:"tls_max_version,attr"`
DisableKeepAlives *bool `xml:"disable_keep_alives,attr"`
DisableCompression *bool `xml:"disable_compression,attr"`
MaxIdleConns *int `xml:"max_idle_conns,attr"`
MaxIdleConnsPerHost *int `xml:"max_idle_conns_per_host,attr"`
MaxConnsPerHost *int `xml:"max_conns_per_host,attr"`
IdleConnTimeout string `xml:"idle_conn_timeout,attr"`
ResponseHeaderTimeout string `xml:"response_header_timeout,attr"`
ExpectContinueTimeout string `xml:"expect_continue_timeout,attr"`
MaxResponseHeaderBytes *int64 `xml:"max_response_header_bytes,attr"`
WriteBufferSize *int `xml:"write_buffer_size,attr"`
ReadBufferSize *int `xml:"read_buffer_size,attr"`
ForceAttemptHTTP2 *bool `xml:"force_attempt_http2,attr"`
}
HTTPClientElement maps all attributes from the HttpClientType XML schema[cite: 1].
func (*HTTPClientElement) GetOutputVariable ΒΆ added in v1.2.11
func (e *HTTPClientElement) GetOutputVariable() string
Helper methods to identify target output variables
func (*HTTPClientElement) GetStatusCodeVariable ΒΆ added in v1.2.11
func (e *HTTPClientElement) GetStatusCodeVariable() string
type JsonPathElement ΒΆ added in v1.2.13
type JsonPathElement struct {
ID string `xml:"id,attr"`
File string `xml:"file,attr"`
Var string `xml:"var,attr"`
Path string `xml:"path,attr"`
JSONPath string `xml:"jsonpath,attr"`
Content string `xml:",chardata"` // Captures inner element body text
Mode string `xml:"mode,attr"` // "value", "json", "json_array"
OutputVar string `xml:"output_var,attr"`
OutVar string `xml:"out_var,attr"`
}
func (*JsonPathElement) GetJSONPath ΒΆ added in v1.2.13
func (j *JsonPathElement) GetJSONPath() string
func (*JsonPathElement) GetOutputVar ΒΆ added in v1.2.13
func (j *JsonPathElement) GetOutputVar() string
type NodeKind ΒΆ
type NodeKind int
NodeKind represents the structural type of a PipelineNode.
const ( // NodeScript represents a leaf script execution step. NodeScript NodeKind = iota // NodeGroup represents a simple sequence container of nodes. NodeGroup // NodeIf represents a conditional branching sequence. NodeIf // NodeForEach represents an iterative driver loop. NodeForEach // NodeParallel represents a concurrent block container. NodeParallel // NodeWhile represents a condition-controlled iteration loop. NodeWhile // NodeHTTPClient represents an HTTP client execution step. NodeHTTPClient // Added NodeHTTPClient enum // NodeTemplate represents a template inclusion step. NodeTemplate // New enum item // NodeFileSave represents a file save operation step. NodeFileSave // New enum item for file save operation // NodeFileRead represents a file read operation step. NodeFileRead // New enum item for file read operation NodeExcelRead // New enum item for Excel read operation NodeExcelWrite // New enum item for Excel write operation NodeXMLXPath // New enum item for XML XPath extraction NodeJSONPath // New enum item for JSON path extraction NodeYAMLPath // New enum item for YAML path extraction NodeSQL // New enum item for standard SQL execution NodeSQLBulk // New enum item for bulk SQL execution NodeAssert // New enum item for assert operation )
type PipelineConfig ΒΆ added in v1.2.16
type PipelineConfig struct {
Variables []VariableConfig
Databases []DatabaseConfig
PreflightNodes []PipelineNode
FlowNodes []PipelineNode
}
PipelineConfig encapsulates the complete parsed AST structure.
func ParseXMLConfig ΒΆ
func ParseXMLConfig(xmlData []byte) (PipelineConfig, error)
ParseXMLConfig parses XML pipeline config definitions into separate Preflight and Flow ASTs.
type PipelineNode ΒΆ
type PipelineNode struct {
Kind NodeKind // Struct/flow type of the node
MaxThreads int // Concurrency limit (only used for NodeParallel)
MaxIterations int // Infinite loop safety limit (only used for NodeWhile)
Script *ScriptItem // Leaf script item payload (only used for NodeScript)
HTTPClient *HTTPClientElement // Added HTTP payload
GroupID string // Structural/group name or ID
IfVar string // Condition driver variable name
IfEquals string // Expected variable value to match
ForEachScript *ScriptItem // Iterator driver script config (only used for NodeForEach)
Children []PipelineNode // List of sequential child execution steps
ElseNodes []PipelineNode // Else branching steps (only used for NodeIf)
Transaction bool // Start transaction for this group
DBName string // Database name for the transaction
Template *TemplateElement // New payload field for template inclusion step
FileSave *FileSaveElement // New payload field for file save operation
FileRead *FileReadElement // New payload field for file read operation
ExcelRead *ExcelReadElement // New payload field for Excel read operation
ExcelWrite *ExcelWriteElement // New payload field for Excel write operation
XmlXPath *XmlXPathElement // New payload field for XML XPath extraction
JsonPath *JsonPathElement // New payload field for JSON path extraction
YamlPath *YamlPathElement // New payload field for YAML path extraction
Assert *AssertElement // New enum item for assert operation
}
PipelineNode is an AST node in the pipeline execution tree.
type Registry ΒΆ
type Registry struct {
// contains filtered or unexported fields
}
Registry is a thread-safe container that manages active database connection pools and dynamic pipeline environment variables.
func NewRegistry ΒΆ
func NewRegistry() *Registry
NewRegistry instantiates and returns an empty Registry context.
func (*Registry) CloseDatabases ΒΆ
func (r *Registry) CloseDatabases()
CloseDatabases closes all open database connections tracked inside the registry and removes them.
func (*Registry) CopyVariables ΒΆ
CopyVariables creates and returns a thread-safe snapshot map of all current environment variables.
func (*Registry) GetDB ΒΆ
GetDB returns the direct sql.DB pointer for the requested database name, if registered.
func (*Registry) GetDBHandle ΒΆ
GetDBHandle returns the DBHandle wrapper (containing sql.DB and Driver name) for the database.
func (*Registry) GetVar ΒΆ
GetVar retrieves an environment variable's raw interface value in a thread-safe manner.
func (*Registry) GetVarBool ΒΆ
func (*Registry) GetVarFloat ΒΆ
func (*Registry) GetVarInt ΒΆ
GetVarInt retrieves a variable and returns its value as an integer (parsing strings if necessary).
func (*Registry) GetVarString ΒΆ
GetVarString retrieves a variable and returns its value formatted as a string.
func (*Registry) GetVarTime ΒΆ added in v1.2.8
GetVarTime retrieves a variable and returns its value as time.Time (parsing string dates if necessary).
func (*Registry) InitDatabases ΒΆ
func (r *Registry) InitDatabases(configs []DatabaseConfig) error
InitDatabases opens connection pools for all supplied DatabaseConfigs with variable interpolation in connection strings.
func (*Registry) InitVariables ΒΆ
func (r *Registry) InitVariables(configs []VariableConfig) error
InitVariables registers and parses multiple environment variables based on type configuration.
func (*Registry) MergeVariables ΒΆ added in v1.2.8
MergeVariables copies variable key-value pairs into the parent registry.
type ScriptItem ΒΆ
type ScriptItem struct {
ID string // Unique identifier of the script
Language string // Language identifier (sql or go)
DBName string // Target database identifier for SQL queries
TargetDB string // Destination database identifier for streaming ETL
TargetTable string // Destination table name for streaming ETL
BatchSize int // Maximum rows loaded per batch
VarName string // Input environment variable to pull script code from dynamically
OutputVar string // Environment variable to store the command's outputs or logs into
Code string // Inner script text/payload
Tablock bool // Acquire table lock for minimal logging on SQL Server
CheckConstraints bool // Evaluate constraints during MSSQL bulk insert
FireTriggers bool // Execute target table triggers during MSSQL bulk insert
KeepNulls bool // Preserve explicit NULL values during MSSQL bulk insert
}
ScriptItem represents an executable script payload (either SQL or Go) with metadata.
type ScriptResult ΒΆ
type ScriptResult struct {
ScriptID string `json:"script_id"` // Unique script identifier
ReturnCode any `json:"return_code"` // 0 on success, or error details on failure
ResultsString string `json:"results_string"` // Output logs, driver queries, or execution results
Duration string `json:"duration,omitempty"` // Cumulative execution time
}
ScriptResult represents the complete outcome of a single executed script or loop block.
type TemplateElement ΒΆ added in v1.2.13
type TemplateElement struct {
ID string `xml:"id,attr"`
Name string `xml:"name,attr"`
File string `xml:"file,attr"`
Engine string `xml:"engine,attr"`
OutputVar string `xml:"output_var,attr"`
Var string `xml:"var,attr"`
Content string `xml:",chardata"`
}
func (*TemplateElement) GetOutputVar ΒΆ added in v1.2.13
func (t *TemplateElement) GetOutputVar() string
type VariableConfig ΒΆ
type VariableConfig struct {
Name string // Name of the variable
Type string // Type of the variable (e.g. string, int, bool, float)
Value string // Value of the variable as a raw string
}
VariableConfig represents an individual environment variable loaded from XML.
type XmlXPathElement ΒΆ added in v1.2.13
type XmlXPathElement struct {
ID string `xml:"id,attr"`
File string `xml:"file,attr"`
Var string `xml:"var,attr"`
XPath string `xml:"xpath,attr"`
Content string `xml:",chardata"` // Captures inner element body text
Mode string `xml:"mode,attr"` // "text", "xml", "json_array"
OutputVar string `xml:"output_var,attr"`
}
func (*XmlXPathElement) GetXPath ΒΆ added in v1.2.13
func (x *XmlXPathElement) GetXPath() string
type YamlPathElement ΒΆ added in v1.2.13
type YamlPathElement struct {
ID string `xml:"id,attr"`
File string `xml:"file,attr"`
Var string `xml:"var,attr"`
Path string `xml:"path,attr"`
YAMLPath string `xml:"yamlpath,attr"`
Content string `xml:",chardata"` // Captures inner element body text
Mode string `xml:"mode,attr"` // "value", "json", "json_array", "yaml"
OutputVar string `xml:"output_var,attr"`
OutVar string `xml:"out_var,attr"`
}
func (*YamlPathElement) GetOutputVar ΒΆ added in v1.2.13
func (y *YamlPathElement) GetOutputVar() string
func (*YamlPathElement) GetYAMLPath ΒΆ added in v1.2.13
func (y *YamlPathElement) GetYAMLPath() string