diff options
author | Silvan Jegen <s.jegen@gmail.com> | 2016-12-16 19:33:35 +0100 |
---|---|---|
committer | Silvan Jegen <s.jegen@gmail.com> | 2016-12-16 19:33:35 +0100 |
commit | aa6ce8af52758fb932d1b011f10be307f3d88f80 (patch) | |
tree | ba5974ff1abfdecf0504b4952dd1295ba262e11c /filter | |
parent | 8ab189a57a3cce1db56dde190bf354f0c26e9efa (diff) |
Add an HTTP filter
Diffstat (limited to 'filter')
-rw-r--r-- | filter/http.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/filter/http.go b/filter/http.go new file mode 100644 index 0000000..97fffa7 --- /dev/null +++ b/filter/http.go @@ -0,0 +1,35 @@ +package filter + +import ( + "bytes" + "io/ioutil" + "net/http" + + "github.com/Shugyousha/stasher/work" +) + +type HTTPFilter struct { + url string +} + +func NewHTTPFilter(url string) *HTTPFilter { + 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 +} |