From 2eb6ecf4e9d8040bd2a698dbfa80bcd45b0c371e Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Sat, 21 Jan 2017 12:34:51 +0100 Subject: Use the registry for filter modules as well --- filter/http/http.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 filter/http/http.go (limited to 'filter/http') diff --git a/filter/http/http.go b/filter/http/http.go new file mode 100644 index 0000000..e3d447b --- /dev/null +++ b/filter/http/http.go @@ -0,0 +1,42 @@ +package http + +import ( + "bytes" + "io/ioutil" + "net/http" + + "github.com/Shugyousha/stasher/filter" + "github.com/Shugyousha/stasher/registry" + "github.com/Shugyousha/stasher/work" +) + +func init() { + registry.Filterregistry["http"] = New +} + +type HTTPFilter struct { + url string +} + +func New(kv map[string]string) filter.Filter { + url := kv["url"] + return &HTTPFilter{url: url} +} + +func (hf *HTTPFilter) Filter(w *work.Work) *work.Work { + resp, err := http.Post(hf.url, "application/json", bytes.NewReader(w.Data)) + if err != nil { + w.Err = err + return w + } + defer resp.Body.Close() + + filtered, err := ioutil.ReadAll(resp.Body) + if err != nil { + w.Err = err + return w + } + + w.Data = filtered + return w +} -- cgit v1.2.1-18-gbd029