added serve-http option

This commit is contained in:
Mahmoud Rahbar Azad 2018-10-26 22:31:39 +02:00
parent c0539ade72
commit 4a726291a2
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: 7DBBD39E2BFEB784
9 changed files with 313 additions and 96 deletions

27
writer/json.go Normal file
View file

@ -0,0 +1,27 @@
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))
}

28
writer/table.go Normal file
View file

@ -0,0 +1,28 @@
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()
}

7
writer/writer.go Normal file
View file

@ -0,0 +1,7 @@
package writer
import "github.com/mrahbar/my-bloody-hetzner-sb-notifier/hetzner"
type Writer interface {
Print(deals hetzner.Deals)
}