Skip to content

Instantly share code, notes, and snippets.

@adammck
Last active August 29, 2015 14:08
Show Gist options
  • Save adammck/9171b675a0cc4dc5c009 to your computer and use it in GitHub Desktop.
Save adammck/9171b675a0cc4dc5c009 to your computer and use it in GitHub Desktop.
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