package main
import (
"net/http"
"os"
"strings"
)
func shareDir(dirName string,port string,ch chan bool){
h := http.FileServer(http.Dir(dirName))
err := http.ListenAndServe(":"+port,h)
if err
!= nil {
println("ListenAndServe
: ",err.Error())
ch <- false
}
}
func main(){
ch := make(chan bool)
port := "8000" //Default
port
if len(os.Args)>1 {
port = strings.Join(os.Args[1:2],"")
}
go shareDir(".",port,ch)
println("Listening
on port ",port,"...")
bresult := <-ch
if false ==
bresult {
println("Listening
on port ",port,"
failed")
}
}
转载自:http://www.cnblogs.com/MikeZhang/archive/2012/03/13/httpShareGolang20120312.html