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 }