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/table.go
2018-10-26 22:31:39 +02:00

28 lines
704 B
Go

package writer
import (
"fmt"
"github.com/mrahbar/my-bloody-hetzner-sb-notifier/hetzner"
"io"
"text/tabwriter"
)
type TableWriter struct {
tabWriter *tabwriter.Writer
}
func NewTableWriter(output io.Writer)*TableWriter {
return &TableWriter{
tabwriter.NewWriter(output, 0, 8, 2, ' ', tabwriter.Debug|tabwriter.AlignRight),
}
}
func (c *TableWriter) Print(deals hetzner.Deals) {
fmt.Fprintf(c.tabWriter,"Got %d offers. Filtered offers: %d\n", deals.ResultStats.OriginalCount, deals.ResultStats.FilteredCount)
fmt.Fprintf(c.tabWriter, "%s\n", deals.Servers[0].Header())
for _, server := range deals.Servers {
fmt.Fprintf(c.tabWriter, "%s\n", server.ToString())
}
c.tabWriter.Flush()
}