EncodeContext writes the YAML encoding of v to the stream with context.Context.
(ctx context.Context, v interface{})
| 88 | |
| 89 | // EncodeContext writes the YAML encoding of v to the stream with context.Context. |
| 90 | func (e *Encoder) EncodeContext(ctx context.Context, v interface{}) error { |
| 91 | node, err := e.EncodeToNodeContext(ctx, v) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | if err := e.setCommentByCommentMap(node); err != nil { |
| 96 | return err |
| 97 | } |
| 98 | if !e.written { |
| 99 | e.written = true |
| 100 | } else { |
| 101 | // write document separator |
| 102 | _, _ = e.writer.Write([]byte("---\n")) |
| 103 | } |
| 104 | var p printer.Printer |
| 105 | _, _ = e.writer.Write(p.PrintNode(node)) |
| 106 | return nil |
| 107 | } |
| 108 | |
| 109 | // EncodeToNode convert v to ast.Node. |
| 110 | func (e *Encoder) EncodeToNode(v interface{}) (ast.Node, error) { |
no test coverage detected