parse

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Select = struct {
	Element func(...string) Selector
}{
	Element: func(elements ...string) Selector {
		return func(path string) bool {
			name := path
			if slash := strings.LastIndexByte(path, '/'); slash >= 0 {
				name = path[slash+1:]
			}
			for _, element := range elements {
				if name == element {
					return true
				}
			}
			return false
		}
	},
}

Functions

func GetAttr

func GetAttr(elem xml.StartElement, name string) string

func GetResults

func GetResults[T any](rs *ResultStore, resultType string) []T

func LoadFromScope

func LoadFromScope[T any](hctx *HandlerContext, key string) (T, bool)

func ScopeLoad

func ScopeLoad[T any](scope *ScopeContext, key string) (T, bool)

func ScopeStore

func ScopeStore[T any](scope *ScopeContext, key string, value T)

func SessionLoad

func SessionLoad[T any](sm *SessionManager, path string) (T, bool)

func SessionStore

func SessionStore[T any](sm *SessionManager, path string, value T)

Type-safe session storage

func StoreInScope

func StoreInScope[T any](hctx *HandlerContext, key string, value T)

Types

type ContextServices

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

type FuncHandler

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

func (*FuncHandler) End

func (f *FuncHandler) End() HandlerFunc

func (*FuncHandler) Selector

func (f *FuncHandler) Selector() Selector

func (*FuncHandler) Start

func (f *FuncHandler) Start() HandlerFunc

type Handler

type Handler interface {
	Start() HandlerFunc
	End() HandlerFunc
}

func NewFuncHandler

func NewFuncHandler(selector Selector, start, end HandlerFunc) Handler

type HandlerContext

type HandlerContext struct {
	Path    string
	Element xml.StartElement
	Text    string
	// contains filtered or unexported fields
}

HandlerContext is the immutable XML view plus the small set of shared services handlers need while a token is processed.

func NewHandlerContext

func NewHandlerContext(path string, element xml.StartElement, text string, services *ContextServices) *HandlerContext

func (*HandlerContext) IncrementCounter

func (hctx *HandlerContext) IncrementCounter(name string)

func (*HandlerContext) RecordDuration

func (hctx *HandlerContext) RecordDuration(name string, duration time.Duration)

func (*HandlerContext) RecordError

func (hctx *HandlerContext) RecordError(err error)

func (*HandlerContext) StoreResult

func (hctx *HandlerContext) StoreResult(resultType string, result any)

type HandlerFunc

type HandlerFunc func(ctx context.Context, hctx *HandlerContext) error

HandlerFunc is the basic handler signature for both Start and End

type MetricsCollector

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

func NewMetricsCollector

func NewMetricsCollector() *MetricsCollector

func (*MetricsCollector) IncrementCounter

func (m *MetricsCollector) IncrementCounter(name string)

func (*MetricsCollector) RecordDuration

func (m *MetricsCollector) RecordDuration(name string, duration time.Duration)

func (*MetricsCollector) RecordError

func (m *MetricsCollector) RecordError(error, string)

func (*MetricsCollector) ToJSON

func (m *MetricsCollector) ToJSON() map[string]any

type Middleware

type Middleware func(HandlerFunc) HandlerFunc

Middleware wraps a HandlerFunc to add behavior

func Chain

func Chain(middlewares ...Middleware) Middleware

Chain combines multiple middleware into one

func MetricsMiddleware

func MetricsMiddleware(metricName string) Middleware

MetricsMiddleware now uses the clean API

func When

func When(condition func(*HandlerContext) bool) Middleware

Conditional execution

type ParseOptions

type ParseOptions struct {
	// Middleware to apply to all handlers
	GlobalStartMiddleware []Middleware
	GlobalEndMiddleware   []Middleware

	// Performance tuning
	EnableMetrics bool

	// Error handling
	StopOnError bool
}

ParseOptions configures the parsing behavior

func DefaultParseOptions

func DefaultParseOptions() ParseOptions

DefaultParseOptions provides sensible defaults

type ParseResult

type ParseResult struct {
	StartTime time.Time
	EndTime   time.Time
	Duration  time.Duration

	Engine *ProcessingEngine
	Errors []error
}

func (*ParseResult) Results

func (pr *ParseResult) Results() *ResultStore

Results returns the result collector

type Parser

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

func NewParser

func NewParser(opts ParseOptions) *Parser

func (*Parser) Close

func (p *Parser) Close(time.Duration) error

Close preserves a symmetric lifecycle for callers. All parser resources are synchronous, so there is nothing to drain.

func (*Parser) Metrics

func (p *Parser) Metrics() map[string]interface{}

Metrics returns current metrics

func (*Parser) Parse

func (p *Parser) Parse(ctx context.Context, r io.Reader) (*ParseResult, error)

func (*Parser) ParseFile

func (p *Parser) ParseFile(ctx context.Context, filename string) (*ParseResult, error)

ParseFile processes an XML file

func (*Parser) Register

func (p *Parser) Register(handler Handler, selector Selector) *Parser

Register registers a handler with an explicit selector.

func (*Parser) RegisterHandler

func (p *Parser) RegisterHandler(handler Handler) *Parser

RegisterHandler registers a handler that exposes its own Selector().

type ProcessingEngine

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

func NewProcessingEngine

func NewProcessingEngine() *ProcessingEngine

func (*ProcessingEngine) CreateContext

func (pe *ProcessingEngine) CreateContext(path string, element xml.StartElement, text string) *HandlerContext

type ResultStore

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

ResultStore is the deliberately small handoff between streaming Pass 1 handlers and the ARM pipeline.

func NewResultStore

func NewResultStore() *ResultStore

func (*ResultStore) StoreWithPath

func (rs *ResultStore) StoreWithPath(resultType, _ string, result any)

type Route

type Route struct {
	Handler  Handler
	Selector Selector
}

type Router

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

func NewRouter

func NewRouter() *Router

func (*Router) Match

func (r *Router) Match(path string) []Handler

func (*Router) Register

func (r *Router) Register(handler Handler, selector Selector) *Router

type ScopeContext

type ScopeContext struct {
	Parent *ScopeContext
	// contains filtered or unexported fields
}

type ScopeStack

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

func NewScopeStack

func NewScopeStack() *ScopeStack

func (*ScopeStack) Current

func (sm *ScopeStack) Current() *ScopeContext

func (*ScopeStack) Pop

func (sm *ScopeStack) Pop()

func (*ScopeStack) Push

func (sm *ScopeStack) Push(_ string)

type Selectable

type Selectable interface {
	Selector() Selector
}

Selectable is implemented by handlers that carry their own path selector.

type Selector

type Selector func(path string) bool

type SessionManager

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

func NewSessionManager

func NewSessionManager() *SessionManager

func (*SessionManager) Delete

func (sm *SessionManager) Delete(path string)

func (*SessionManager) Load

func (sm *SessionManager) Load(path string) (any, bool)

func (*SessionManager) Store

func (sm *SessionManager) Store(path string, data any)

type StreamingHandler

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

func NewStreamingHandler

func NewStreamingHandler(router *Router, engine *ProcessingEngine) *StreamingHandler

func (*StreamingHandler) HandleCharData

func (h *StreamingHandler) HandleCharData(ctx context.Context, cd xml.CharData) error

func (*StreamingHandler) HandleEndElement

func (h *StreamingHandler) HandleEndElement(ctx context.Context, ee xml.EndElement) error

func (*StreamingHandler) HandleStartElement

func (h *StreamingHandler) HandleStartElement(ctx context.Context, se xml.StartElement) error

type TypedHandler

type TypedHandler[TContext any, TResult any] struct {
	// contains filtered or unexported fields
}

TypedHandler now composes middleware with typed processing

func (*TypedHandler[T, R]) End

func (h *TypedHandler[T, R]) End() HandlerFunc

func (*TypedHandler[T, R]) Selector

func (h *TypedHandler[T, R]) Selector() Selector

Selector returns the path selector for this handler.

func (*TypedHandler[T, R]) Start

func (h *TypedHandler[T, R]) Start() HandlerFunc

type TypedHandlerBuilder

type TypedHandlerBuilder[TContext any, TResult any] struct {
	// contains filtered or unexported fields
}

Builder pattern for clean configuration

func NewTypedHandlerBuilder

func NewTypedHandlerBuilder[TContext any, TResult any](name string, selector Selector) *TypedHandlerBuilder[TContext, TResult]

func (*TypedHandlerBuilder[T, R]) Build

func (b *TypedHandlerBuilder[T, R]) Build() Handler

func (*TypedHandlerBuilder[T, R]) WithContextCreator

func (b *TypedHandlerBuilder[T, R]) WithContextCreator(f func(*HandlerContext) T) *TypedHandlerBuilder[T, R]

func (*TypedHandlerBuilder[T, R]) WithEndProcessor

func (b *TypedHandlerBuilder[T, R]) WithEndProcessor(f func(context.Context, T, *HandlerContext) (R, error)) *TypedHandlerBuilder[T, R]

func (*TypedHandlerBuilder[T, R]) WithResultHandler

func (b *TypedHandlerBuilder[T, R]) WithResultHandler(f func(context.Context, R, *HandlerContext) error) *TypedHandlerBuilder[T, R]

func (*TypedHandlerBuilder[T, R]) WithStartMiddleware

func (b *TypedHandlerBuilder[T, R]) WithStartMiddleware(m ...Middleware) *TypedHandlerBuilder[T, R]

func (*TypedHandlerBuilder[T, R]) WithStartProcessor

func (b *TypedHandlerBuilder[T, R]) WithStartProcessor(f func(context.Context, T, *HandlerContext) error) *TypedHandlerBuilder[T, R]

Jump to

Keyboard shortcuts

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