File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package internal
2+
3+ import (
4+ "encoding/json"
5+
6+ "go.yaml.in/yaml/v2"
7+ )
8+
9+ type OutputFormater [T any ] interface {
10+ Format (input T ) (string , error )
11+ }
12+
13+ type YamlOutputFormater struct {}
14+
15+ var _ OutputFormater [any ] = (* YamlOutputFormater )(nil )
16+
17+ func (f * YamlOutputFormater ) Format (input any ) (string , error ) {
18+ yamled , err := yaml .Marshal (input )
19+ if err != nil {
20+ return "" , err
21+ }
22+ return string (yamled ), nil
23+ }
24+
25+ type JsonOutputFormater struct {}
26+
27+ var _ OutputFormater [any ] = (* JsonOutputFormater )(nil )
28+
29+ func (f * JsonOutputFormater ) Format (input any ) (string , error ) {
30+ jsoned , err := json .MarshalIndent (input , "" , "\t " )
31+ if err != nil {
32+ return "" , err
33+ }
34+ return string (jsoned ), nil
35+ }
36+
37+ type ArrayOutputFormater struct {}
38+
39+ var _ OutputFormater [ArrayInput ] = (* ArrayOutputFormater )(nil )
40+
41+ type ArrayInput struct {
42+ Header []string
43+ Content [][]string
44+ }
45+ func (f * ArrayOutputFormater ) Format (input ArrayInput ) (string , error ) {
46+ jsoned , err := json .MarshalIndent (input , "" , "\t " )
47+ if err != nil {
48+ return "" , err
49+ }
50+ return string (jsoned ), nil
51+ }
You can’t perform that action at this time.
0 commit comments