From e17249cbe61a4d85a2b46336c1acf2f4ccba4fe2 Mon Sep 17 00:00:00 2001 From: Eliot Whalan Date: Fri, 10 Jun 2016 23:56:42 +1000 Subject: [PATCH] Setup simple webserver and get basic paste saving working --- main.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..88317c6 --- /dev/null +++ b/main.go @@ -0,0 +1,25 @@ +package main + +import ( + "io/ioutil" + "net/http" +) + +func check(e error) { + if e != nil { + panic(e) + } +} + +func pasteHandler(w http.ResponseWriter, req *http.Request) { + buf, _ := ioutil.ReadAll(req.Body) + paste := buf[89 : len(buf)-46] + err := ioutil.WriteFile("/tmp/dat1", paste, 0644) + check(err) +} + +func main() { + http.HandleFunc("/", pasteHandler) + http.ListenAndServe(":8080", nil) + +}