This repository has been archived on 2021-09-02. You can view files and clone it, but cannot push or open issues or pull requests.
my-bloody-hetzner-sb-notifier/writer/json.go
2018-10-26 22:31:39 +02:00

27 lines
455 B
Go

package writer
import (
"encoding/json"
"fmt"
"github.com/mrahbar/my-bloody-hetzner-sb-notifier/hetzner"
"io"
)
type JsonWriter struct {
output io.Writer
}
func NewJsonWriter(output io.Writer)*JsonWriter {
return &JsonWriter{
output:output,
}
}
func (c *JsonWriter) Print(deals hetzner.Deals) {
b, err := json.Marshal(deals)
if err != nil {
fmt.Fprintf(c.output, "{\"error\": \"%s\"}", err)
return
}
fmt.Fprint(c.output, string(b))
}