在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
httpserver.go package main import ( "net/http" "flag" "fmt" "log" ) func main() { var dir string flag.StringVar(&dir, "d", ".", "web dir") var port *int port = flag.Int("p", 0, "port: must input") var host string flag.StringVar(&host,"h","","host") flag.Parse() if *port<=0 || *port>65535 { flag.Usage() return } var addr = fmt.Sprintf("%s:%d", host,*port) log.Printf("Listenning http://%s ...", addr) http.Handle("/", http.FileServer(http.Dir(dir))) err := http.ListenAndServe(addr, nil) if err!= nil { log.Fatal("ERROR:",err) } }
$ go run httpserver.go -p 8080
|
请发表评论