Apply returns a YAML document that has been mutated per patch
(doc []byte)
| 14 | |
| 15 | // Apply returns a YAML document that has been mutated per patch |
| 16 | func (p Patch) Apply(doc []byte) ([]byte, error) { |
| 17 | if len(p) == 0 { |
| 18 | return doc, nil |
| 19 | } |
| 20 | |
| 21 | node := &yaml.Node{} |
| 22 | err := yamlutil.Unmarshal(doc, node) |
| 23 | if err != nil { |
| 24 | return nil, fmt.Errorf("failed unmarshaling doc: %s\n\n%s", string(doc), err) |
| 25 | } |
| 26 | |
| 27 | for _, op := range p { |
| 28 | err = op.Perform(node) |
| 29 | if err != nil { |
| 30 | return nil, err |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | return yaml.Marshal(node) |
| 35 | } |
| 36 | |
| 37 | func NewNode(raw *interface{}) (*yaml.Node, error) { |
| 38 | doc, err := yaml.Marshal(raw) |