HTTP sharing using the go Language

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.