package main

import (
	"flag"
	"log"
	"net/http"
	"strconv"
)

var fs http.Handler

func main() {
	// setup, then parse flags
	var port int
	var host string

	flag.IntVar(&port, "port", 3000, "The port to bind to")
	flag.StringVar(&host, "host", "127.0.0.1", "The host to bind to")
	flag.Parse()

	addr := host + ":" + strconv.Itoa(port)

	fs = http.FileServer(http.Dir("."))
	http.HandleFunc("/", logHandler)

	log.Printf("Listening to %s on port %d...", host, port)

	http.ListenAndServe(addr, nil)
}

// Just logs the request to the console before passing it to the
// http.FileServer
func logHandler(w http.ResponseWriter, r *http.Request) {
	log.Printf("[%s] %s", r.Method, r.URL)
	fs.ServeHTTP(w, r)
}

package main

import (
	"flag"
	"github.com/ciarand/martini-fileindex"
	"github.com/codegangsta/martini"
	"net/http"
)

func main() {
	port := parseFlags()

	m := martini.Classic()

	m.Handlers(
		martini.Logger(),
		martini.Static("."),
		fileindex.ListFiles("."),
	)

	http.ListenAndServe(":"+port, m)
}

func parseFlags() (port string) {
	// setup, then parse flags
	flag.StringVar(&port, "port", "3000", "The port to bind to")
	flag.Parse()

	return port
}

Use Martini, use my "martini-fileindex" package
Use Martini, use my "martini-fileindex" package

Martini has logging builtin, it makes it much simpler. Also removing the
host flag - this isn't intended for anything but local dev testing, no
point in giving people the ability to make really, really, really bad
decisions.
