container

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeContainer

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

CodeContainer holds an in-memory mapping of file paths to contents and offers helpers to render inputs, apply outputs, and persist to disk.

func MustNewCodeContainerFromFS

func MustNewCodeContainerFromFS(baseDir string, paths []string) *CodeContainer

MustNewCodeContainerFromFS is a helper that panics if NewCodeContainerFromFS fails.

func NewCodeContainer

func NewCodeContainer(files map[string]string) *CodeContainer

NewCodeContainer constructs a container with a copy of the provided files map.

func NewCodeContainerFromFS

func NewCodeContainerFromFS(baseDir string, paths []string) (*CodeContainer, error)

NewCodeContainerFromFS reads given paths from baseDir (or absolute) into a container.

func (*CodeContainer) Apply

func (c *CodeContainer) Apply(output CodeOutput) (string, error)

Apply applies a CodeOutput to the container, mutating its files. Returns a message.

func (*CodeContainer) BuildCodeInput

func (c *CodeContainer) BuildCodeInput(filter []string) CodeInput

BuildCodeInput renders a CodeInput for the selected paths (or all when empty).

func (*CodeContainer) Clone

func (c *CodeContainer) Clone() CodeContainer

Clone returns a copy of the current container.

func (*CodeContainer) Files

func (c *CodeContainer) Files() map[string]string

Files returns a copy of the current in-memory files map.

func (*CodeContainer) Open

func (c *CodeContainer) Open(path string) (string, error)

func (*CodeContainer) Remove

func (c *CodeContainer) Remove(path string) error

func (*CodeContainer) Write

func (c *CodeContainer) Write(path, content string) error

func (*CodeContainer) WriteToFiles

func (c *CodeContainer) WriteToFiles() error

WriteToFiles applies all changes to the container to the file system.

type CodeFile

type CodeFile struct {
	Path    string `xml:"path,attr"`
	Content string `xml:"-"`
}

func (CodeFile) MarshalXML

func (f CodeFile) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML customizes File serialization to wrap content in CDATA

type CodeInput

type CodeInput struct {
	XMLName xml.Name   `xml:"CodeInput"`
	Files   []CodeFile `xml:"File"`
}

The Code Input context is xml struct of all code files. Codes are wrapped with <![CDATA[ and ]]> to avoid xml escaping. Example: <CodeInput>

<File path="main.go"><![CDATA[
  package main
  func main() {
    fmt.Println("Hello, World!")
  }
]]></File>
<File path="main_test.go"><![CDATA[
  ...
]]></File>

</CodeInput>

func BuildCodeInput

func BuildCodeInput(files map[string]string, filter []string) CodeInput

BuildCodeInput builds a CodeInput document from the provided files map. The order of files is deterministic (sorted by path). If filter is provided, only those paths (that exist in files) are included.

func (CodeInput) ToXML

func (ci CodeInput) ToXML() (string, error)

ToXML renders this CodeInput as an XML string with CDATA sections for file contents. We write CDATA blocks explicitly to preserve content verbatim.

type CodeOutput

type CodeOutput struct {
	XMLName xml.Name `xml:"CodeOutput"`
	Version string   `xml:"version,attr,omitempty"`
	Patch   string   `xml:",chardata"`
}

The Code Output context is xml struct for all updated code files. It is a simple SRD diff text format. Example: <CodeOutput version="first_draft"> *** Begin Patch *** Update File: notes.txt @@ hello -hello +hi

world

*** End Patch </CodeOutput>

func ParseCodeOutput

func ParseCodeOutput(xmlPayload string) (CodeOutput, error)

ParseCodeOutput parses a CodeOutput XML payload.

Jump to

Keyboard shortcuts

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