Before meArticle(Http://www.cnblogs.com/MikeZhang/archive/2012/02/11/httpFileSharePythonAndGo.html).GoLanguage implementationHTTPShare, thisProgramI have been using it.PythonMore flexible: If no port is specified, it is enabled by default.8000 ......
YesPythonNot powerful, not to mention, only one client is allowed, decisive decision to write one!
Okay, no more nonsense,CodeAs follows:
/*
File: httpshare. Go Author: Mike E-mail: Mike_Zhang@live.com */ PackageMain Import( "Net/HTTP" "OS" "Strings" ) FuncIncludir (dirnameString, PortString, CHChan Bool){ H: = http. fileserver (HTTP. dir (dirname )) Err: = http. listenandserve (":"+ Port, H) IfErr! =Nil{ Println("Listenandserve :", Err. Error ()) Ch <-False } } FuncMain (){ CH: = make ( Chan bool ) Port: = " 8000 " // default port If Len (OS. ARGs)> 1 { Port = strings. Join (OS. ARGs [1:2],"") } go export Dir ( ". " , port, CH) Println("Listening on port", Port,"...") Bresult: = <-CH If false == bresult {Println("Listening on port", Port,"Failed") } }
The running effect is as follows:
1Under normal circumstances:
2When the port is occupied:
Okay, that's all. I hope it will help you.