diff options
Diffstat (limited to 'input/http.go')
-rw-r--r-- | input/http.go | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/input/http.go b/input/http.go deleted file mode 100644 index 285f1f6..0000000 --- a/input/http.go +++ /dev/null @@ -1,45 +0,0 @@ -package input - -import ( - "fmt" - "io/ioutil" - "net/http" - - "github.com/Shugyousha/stasher/work" -) - -type HTTPInput struct { - retchan chan *work.Work - prefix string - port string -} - -func NewHTTPInput(prefix, port string) *HTTPInput { - return &HTTPInput{prefix: prefix, port: port} -} - -func (hi *HTTPInput) httphandler(w http.ResponseWriter, r *http.Request) { - if r.Method != "POST" { - fmt.Printf("Expected POST method was: %q\n", r.Method) - return - } - all, err := ioutil.ReadAll(r.Body) - if err != nil { - fmt.Printf("Error when reading HTTP request body: %q\n", err) - return - } - hi.retchan <- &work.Work{Data: all} -} - -func (hi *HTTPInput) Start() chan *work.Work { - hi.retchan = make(chan *work.Work, 100) - - go func() { - http.HandleFunc("/"+hi.prefix, hi.httphandler) - err := http.ListenAndServe(hi.port, nil) - fmt.Printf("Error when serving HTTP: %q\n", err) - close(hi.retchan) - }() - - return hi.retchan -} |