From e360b95144edd3a19723f92079f48b6763e3be93 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sat, 2 Jul 2016 11:06:00 -0500 Subject: [PATCH] hi --- main.go | 27 +++++++++++++++++++++++++++ server.go | 20 ++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 main.go create mode 100644 server.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..cce4ee5 --- /dev/null +++ b/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "flag" + "fmt" + "net/http" + "os" +) + +var options struct { + Host string +} + +func init() { + flag.StringVar(&options.Host, "host", "0.0.0.0:8000", "http hostname:port to listen on") +} + +func main() { + flag.Parse() + s := server{ + out: os.Stdout, + errors: os.Stderr, + } + if err := http.ListenAndServe(options.Host, &s); err != nil { + fmt.Fprintf(os.Stderr, "error: %v\n", err) + } +} diff --git a/server.go b/server.go new file mode 100644 index 0000000..b9db8f9 --- /dev/null +++ b/server.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "io" + "net/http" +) + +type server struct { + out io.Writer + errors io.Writer +} + +func (s *server) logReceived(r *http.Request) { + fmt.Fprintf(s.out, "> %s\n", r.URL.String()) +} + +func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) { + s.logReceived(r) +}