summaryrefslogtreecommitdiff
path: root/output/http/http.go
blob: 8d1762226399edab169c38c69cfe4e0a6157e267 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package http

import (
	"bytes"
	"net/http"

	"github.com/Shugyousha/stasher/output"
	"github.com/Shugyousha/stasher/registry"
	"github.com/Shugyousha/stasher/work"
)

func init() {
	registry.Outputregistry["http"] = New
}

type HttpOutput struct {
	url string
}

func New(kv map[string]string) output.Output {
	url := kv["url"]
	return &HttpOutput{url: url}
}

func (h *HttpOutput) Output(w *work.Work) error {
	_, err := http.Post(h.url, "application/json", bytes.NewReader(w.Data))
	if err != nil {
		w.SetError(err)
	}

	return err
}