Skip to content

Instantly share code, notes, and snippets.

@mike-zhang
Created October 10, 2012 14:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mike-zhang/3865963 to your computer and use it in GitHub Desktop.
http Share With Trace (golang)
/*
File : httpShareWithTrace.go
Author : Mike
E-Mail : Mike_Zhang@live.com
*/
package main
import (
"net/http"
"os"
"strings"
"log"
)
type TraceHandler struct {
h http.Handler
}
func (r TraceHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
println("get",req.URL.Path," from ",req.RemoteAddr)
r.h.ServeHTTP(w, req)
}
func main() {
port := "8080"//Default port
iflen(os.Args)>1 { port = strings.Join(os.Args[1:2],"")}
h := http.FileServer(http.Dir("."))
http.Handle("/", TraceHandler{h})
println("Listening on port ",port,"...")
log.Fatal("ListenAndServe: ", http.ListenAndServe(":"+port, nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment