package main import ( "fmt" "io/ioutil" "net/http" "strings" "go.wit.com/log" ) // remove '?' part and trailing '/' func cleanURL(url string) string { url = "/" + strings.Trim(url, "/") return url } func okHandler(w http.ResponseWriter, r *http.Request) { log.Info("Got URL Path: ", r.URL.Path) route := cleanURL(r.URL.Path) hostname := r.URL.Query().Get("hostname") msg, err := ioutil.ReadAll(r.Body) // Read the body as []byte if err != nil { log.Info("ReadAll() error =", err) return } if route == "/" { return } if route == "/status" { if hostname == "" { // ignore junk log.Info("hostname was blank") return } log.Info("Got URL msg length:", len(msg)) return } log.Warn("BAD URL =", route) } // starts and sits waiting for HTTP requests func startHTTP() { http.HandleFunc("/", okHandler) p := fmt.Sprintf(":%d", argv.Port) log.Println("Running on port", p) err := http.ListenAndServe(p, nil) if err != nil { log.Println("Error starting server:", err) } }