Last active
August 29, 2015 14:08
-
-
Save adammck/9171b675a0cc4dc5c009 to your computer and use it in GitHub Desktop.
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 ( | |
"flag" | |
"fmt" | |
"io" | |
"log" | |
"net/http" | |
) | |
var host = flag.String("host", "127.0.0.1", "the host to listen on") | |
var port = flag.Int("port", 8000, "the port to listen on") | |
func oneHandler(w http.ResponseWriter, r *http.Request) { | |
w.Header().Set("Content-Type", "text/html;charset=UTF-8") | |
io.WriteString(w, "Don't Panic!") | |
} | |
func twoHandler(w http.ResponseWriter, r *http.Request) { | |
panic("boom!") | |
} | |
func main() { | |
flag.Parse() | |
http.HandleFunc("/one", oneHandler) | |
http.HandleFunc("/two", twoHandler) | |
addr := fmt.Sprintf("%s:%d", *host, *port) | |
log.Printf("Listening on http://%s\n", addr) | |
listenErr := http.ListenAndServe(addr, nil) | |
if listenErr != nil { | |
panic(listenErr) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment