summaryrefslogtreecommitdiff
path: root/filter/http
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2017-01-21 12:34:51 +0100
committerSilvan Jegen <s.jegen@gmail.com>2017-01-21 12:34:51 +0100
commit2eb6ecf4e9d8040bd2a698dbfa80bcd45b0c371e (patch)
tree732693efaf7e9c925a79a8cf412ceb2714d98b3c /filter/http
parent5c24009f2b1fd5a7e5abd4dc33ebdec0c6eaaf25 (diff)
Use the registry for filter modules as well
Diffstat (limited to 'filter/http')
-rw-r--r--filter/http/http.go42
1 files changed, 42 insertions, 0 deletions
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
+}