Created
May 27, 2013 23:52
-
-
Save ewalk153/5659615 to your computer and use it in GitHub Desktop.
Simple web app to listen for incoming requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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