blob: 97fffa7647e8922077bd88209ab30b96bf820e73 (
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
33
34
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
}
|