예제 #1
0
파일: file-server.go 프로젝트: nilslice/s
func main() {
	flag.Parse()

	directory, err := os.Getwd()
	if err != nil {
		exitFromError(err)
	}

	http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
		combinedLogAndFileServer(res, req, directory)
	})

	serverAddress := net.JoinHostPort(*addr, fmt.Sprint(*port))

	fmt.Println(color.YellowString("⎘"), "Serving files from:", color.YellowString(directory))
	fmt.Println(color.GreenString("⤇"), serverAddress)
	fmt.Println(color.RedString("⨂"), "Press 'ctrl+c' to exit.")

	err = http.ListenAndServe(serverAddress, nil)
	// TODO: implement os signal capture to determine if ERRADDRINUSE, etc
	// EADDRINUSE      = Errno(0x62)
	// http://golang.org/pkg/os/signal/
	// http://golang.org/pkg/syscall/#Errno
	if err != nil {
		exitFromError(err)
	}
}
예제 #2
0
파일: file-server.go 프로젝트: nilslice/s
// Log prints the contents of LoggedRequest to the console in a developer friendly
// format. Implement colors for better readability.
func (lr *LoggedRequest) Log() {
	t := "|" + color.MagentaString(lr.timestamp) + "|"
	p := "(" + lr.protocol + ")"
	fmt.Println(
		t,
		color.CyanString(p),
		color.CyanString(lr.method),
		color.YellowString(lr.path),
	)
}