Documentation ¶
Overview ¶
Package yamled implements helpers for in-place editing of YAML sources.
The editing is performed by a golang.org/x/text/transform.Transformer implementation configured with one or more editing operations.
Editing operations are defined as string replacements over selections covering YAML nodes in the YAML source.
Selections are constructed from *yaml.Node value that can be obtained by either manually navigating the YAML node tree or by using other packages like those provided by YAML JSONPointer or YAML JSONPath libraries.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Transformer ¶
type Transformer struct {
// contains filtered or unexported fields
}
A Transformer implements golang.org/x/text/transform.Transformer and can be used to perform precise in-place edits of yaml nodes in an byte stream.
func T ¶
func T(ops ...splice.Op) *Transformer
T creates a transformer that performs YAML-aware edit operations.
Example ¶
ExampleT shows how to use the transformer to edit a YAML source in place. It also shows how the quoting style is preserved.
src := `apiVersion: v1 kind: Service metadata: name: "foo" # some comment namespace: myns ` var root yaml.Node if err := yaml.Unmarshal([]byte(src), &root); err != nil { log.Fatal(err) } // Let's find some nodes in the YAML tree using the YAML JSONPointer library yptr. nameNode, err := yptr.Find(&root, "/metadata/name") if err != nil { log.Fatal(err) } nsNode, err := yptr.Find(&root, "/metadata/namespace") if err != nil { log.Fatal(err) } out, _, err := transform.String(yamled.T( yamled.Node(nameNode).With("bar"), yamled.Node(nsNode).With("otherns"), ), src) if err != nil { log.Fatal(err) } fmt.Println(out)
Output: apiVersion: v1 kind: Service metadata: name: "bar" # some comment namespace: otherns
func (*Transformer) Reset ¶
func (t *Transformer) Reset()
Reset implements the golang.org/x/text/transform.Transformer interface.