feat: go output formatter
This commit is contained in:
@ -54,3 +54,16 @@ func (c *Container) GetValue(key string) (any, error) {
|
||||
|
||||
return item.parseFn(*item.value)
|
||||
}
|
||||
|
||||
// Returns a map of all parameters. Parameters that produce errors during parsing are ignored.
|
||||
func (c *Container) ToMap() (out map[string]any) {
|
||||
out = make(map[string]any)
|
||||
for key := range c.params {
|
||||
v, err := c.GetValue(key)
|
||||
if err == nil {
|
||||
out[key] = v
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import (
|
||||
|
||||
var Formatters = map[string]interfaces.Formatter{
|
||||
"json": &JsonFormatter{},
|
||||
"go": nil,
|
||||
"yaml": nil,
|
||||
"go": &GoFormatter{},
|
||||
"table": nil,
|
||||
"xml": nil,
|
||||
}
|
||||
|
||||
13
core/output/go.go
Normal file
13
core/output/go.go
Normal file
@ -0,0 +1,13 @@
|
||||
package output
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type GoFormatter struct{}
|
||||
|
||||
func (f *GoFormatter) Format(object any) (io.Reader, error) {
|
||||
return strings.NewReader(fmt.Sprintf("%#v", object)), nil
|
||||
}
|
||||
Reference in New Issue
Block a user