Documentation
¶
Index ¶
- type CodeContainer
- func (c *CodeContainer) Apply(output CodeOutput) (string, error)
- func (c *CodeContainer) BuildCodeInput(filter []string) CodeInput
- func (c *CodeContainer) Clone() CodeContainer
- func (c *CodeContainer) Files() map[string]string
- func (c *CodeContainer) Open(path string) (string, error)
- func (c *CodeContainer) Remove(path string) error
- func (c *CodeContainer) Write(path, content string) error
- func (c *CodeContainer) WriteToFiles() error
- type CodeFile
- type CodeInput
- type CodeOutput
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) 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 ¶
func (CodeFile) MarshalXML ¶
MarshalXML customizes File serialization to wrap content in CDATA
type CodeInput ¶
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 ¶
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.
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.