author | Mikael Berthe <mikael@lilotux.net> |
Wed, 21 Mar 2018 13:26:22 +0100 | |
changeset 207 | 56afbe03a7d4 |
parent 84 | 5a894a10304c |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright © 2017 Mikael Berthe <mikael@lilotux.net> |
2 |
// |
|
3 |
// Licensed under the MIT license. |
|
4 |
// Please see the LICENSE file is this directory. |
|
5 |
||
6 |
package printer |
|
7 |
||
8 |
import ( |
|
9 |
"fmt" |
|
10 |
"io" |
|
11 |
"os" |
|
12 |
||
13 |
"github.com/ghodss/yaml" |
|
14 |
) |
|
15 |
||
16 |
// YAMLPrinter represents a YAML printer |
|
17 |
type YAMLPrinter struct { |
|
18 |
} |
|
19 |
||
20 |
// NewPrinterYAML returns a YAML ResourcePrinter |
|
83
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
21 |
func NewPrinterYAML(options Options) (*YAMLPrinter, error) { |
0 | 22 |
return &YAMLPrinter{}, nil |
23 |
} |
|
24 |
||
25 |
// PrintObj sends the object as text to the writer |
|
26 |
// If the writer w is nil, standard output will be used. |
|
27 |
// For YAMLPrinter, the option parameter is currently not used. |
|
28 |
func (p *YAMLPrinter) PrintObj(obj interface{}, w io.Writer, option string) error { |
|
29 |
if w == nil { |
|
30 |
w = os.Stdout |
|
31 |
} |
|
32 |
||
33 |
//yamlEncoder := yaml.NewEncoder(w) |
|
34 |
//return yamlEncoder.Encode(obj) |
|
35 |
||
36 |
output, err := yaml.Marshal(obj) |
|
37 |
if err != nil { |
|
38 |
return err |
|
39 |
} |
|
40 |
_, err = fmt.Fprint(w, string(output)) |
|
41 |
return err |
|
42 |
} |