mirror of
https://github.com/asciimoo/wuzz
synced 2024-11-18 15:25:30 +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]"
|
|
}
|