Skip to content

Instantly share code, notes, and snippets.

@ewalk153
Created May 27, 2013 23:52
Show Gist options
  • Save ewalk153/5659615 to your computer and use it in GitHub Desktop.
Save ewalk153/5659615 to your computer and use it in GitHub Desktop.
Simple web app to listen for incoming requests
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func handler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
log.Println(fmt.Sprintf("URL: %v | Params: %v", r.URL, r.Form))
fmt.Fprintf(w, "Got it!")
}
func port() string {
if len(os.Args) > 1 {
return os.Args[1]
}
return "8080"
}
func main() {
log.Println("Listening on", port())
http.HandleFunc("/", handler)
http.ListenAndServe(":"+port(), nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment