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

28 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))
}