equal
deleted
inserted
replaced
|
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 "encoding/json" |
|
10 "io" |
|
11 "os" |
|
12 ) |
|
13 |
|
14 // JSONPrinter represents a JSON printer |
|
15 type JSONPrinter struct { |
|
16 } |
|
17 |
|
18 // NewPrinterJSON returns a JSON ResourcePrinter |
|
19 func NewPrinterJSON(option string) (*JSONPrinter, error) { |
|
20 return &JSONPrinter{}, nil |
|
21 } |
|
22 |
|
23 // PrintObj sends the object as text to the writer |
|
24 // If the writer w is nil, standard output will be used. |
|
25 // For JSONPrinter, the option parameter is currently not used. |
|
26 func (p *JSONPrinter) PrintObj(obj interface{}, w io.Writer, option string) error { |
|
27 if w == nil { |
|
28 w = os.Stdout |
|
29 } |
|
30 |
|
31 jsonEncoder := json.NewEncoder(w) |
|
32 //jsonEncoder.SetIndent("", " ") |
|
33 return jsonEncoder.Encode(obj) |
|
34 } |