Documentation
¶
Overview ¶
Package up provides functional parsing capabilities for UP documents.
Package up provides templating support for UP documents ¶
Package up defines the core data structures for UP parsing.
Index ¶
- func Unmarshal(data []byte, v any) error
- func UnmarshalDocument(doc *Document, v any) error
- type Block
- type Document
- type List
- type Node
- type ParseFunc
- type Parser
- type Scanner
- type Table
- type TemplateEngine
- func (e *TemplateEngine) ProcessTemplate(filename string) (*Document, error)
- func (e *TemplateEngine) ProcessTemplateFromReader(r io.Reader) (*Document, error)
- func (e *TemplateEngine) WithOptions(opts TemplateOptions) *TemplateEngine
- func (e *TemplateEngine) WithVars(vars map[string]any) *TemplateEngine
- type TemplateOptions
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Unmarshal ¶
Unmarshal parses UP document and stores the result in the value pointed to by v. If v is not a pointer to a struct, Unmarshal returns an error.
Unmarshal uses struct tags to determine how to map UP keys to struct fields:
- `up:"fieldname"` - maps UP key "fieldname" to this struct field
- `up:"fieldname,omitempty"` - omits field if value is empty
- `up:"-"` - ignores this field
Example:
type Config struct {
Host string `up:"host"`
Port int `up:"port"`
Enabled bool `up:"enabled"`
Tags []string `up:"tags"`
Database struct {
Host string `up:"host"`
Port int `up:"port"`
} `up:"database"`
}
func UnmarshalDocument ¶
UnmarshalDocument unmarshals a parsed Document into v.
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser provides configurable parsing functionality.
func NewParser ¶
func NewParser() *Parser
NewParser creates a new Parser with default configuration.
func (*Parser) ParseDocument ¶
ParseDocument parses a UP document from an io.Reader.
func (*Parser) WithDedentFunc ¶
WithDedentFunc configures the dedent function.
func (*Parser) WithSkipComment ¶
WithSkipComment configures the comment skip function.
type Scanner ¶
Scanner wraps a bufio.Scanner with additional functionality.
func NewScanner ¶
NewScanner creates a new Scanner from an io.Reader.
type TemplateEngine ¶
type TemplateEngine struct {
// contains filtered or unexported fields
}
TemplateEngine processes UP templates with overlays, includes, and variables
func NewTemplateEngine ¶
func NewTemplateEngine() *TemplateEngine
NewTemplateEngine creates a new template engine
func (*TemplateEngine) ProcessTemplate ¶
func (e *TemplateEngine) ProcessTemplate(filename string) (*Document, error)
ProcessTemplate processes a UP template file
func (*TemplateEngine) ProcessTemplateFromReader ¶
func (e *TemplateEngine) ProcessTemplateFromReader(r io.Reader) (*Document, error)
ProcessTemplateFromReader processes a template from an io.Reader
func (*TemplateEngine) WithOptions ¶
func (e *TemplateEngine) WithOptions(opts TemplateOptions) *TemplateEngine
WithOptions sets template options
func (*TemplateEngine) WithVars ¶
func (e *TemplateEngine) WithVars(vars map[string]any) *TemplateEngine
WithVars sets initial variables
type TemplateOptions ¶
type TemplateOptions struct {
MergeStrategy string // "deep", "shallow", "replace"
ListStrategy string // "append", "replace", "unique"
BaseDir string // base directory for relative includes
}
TemplateOptions configures template processing