Setup simple webserver and get basic paste saving working

This commit is contained in:
Eliot Whalan 2016-06-10 23:56:42 +10:00
commit e17249cbe6
1 changed files with 25 additions and 0 deletions

25
main.go Normal file
View File

@ -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)
}