mirror of
https://github.com/asciimoo/wuzz
synced 2024-11-14 18:12:55 +00:00
29 lines
507 B
Go
29 lines
507 B
Go
package formatter
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"io"
|
|
|
|
"github.com/nwidger/jsoncolor"
|
|
)
|
|
|
|
type jsonFormatter struct {
|
|
textFormatter
|
|
}
|
|
|
|
func (f *jsonFormatter) Format(writer io.Writer, data []byte) error {
|
|
jsonFormatter := jsoncolor.NewFormatter()
|
|
buf := bytes.NewBuffer(make([]byte, 0, len(data)))
|
|
err := jsonFormatter.Format(buf, data)
|
|
if err == nil {
|
|
writer.Write(buf.Bytes())
|
|
return nil
|
|
}
|
|
return errors.New("json formatter error")
|
|
}
|
|
|
|
func (f *jsonFormatter) Title() string {
|
|
return "[json]"
|
|
}
|