Directory sharing program implemented by GO language

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

In fact, the program is very small, just want to write something.
The night after tomorrow to go back to school exams, in an instant has come out 69 days, more than 2 months.
Salary plus MOM sponsored money, do not know whether can buy a computer, as programmers have been using i3-3217u really uncomfortable.
Go back to the classmate copy dot piece, then copy dot game, OK, go around to the point.
Copy of the game, the simplest way of course is to use a U disk, but the U disk only 16G, a time may not be able to install the next game, and my poor-quality u disk write speed is more than 3M, obviously bad toss.
Another way is to take advantage of the Windows Shared Folders feature, but I tried a few times slow to die, do not know why, so there is not too much fantasy of this way.
Another way is FTP, but students generally do not have FTP services on the computer, the total can not be installed.
So in boredom, I wrote such a small thing, the use of the Go Language Static compilation features, compiled after the network disk, when used at any time to download, directly can be executed, do not need to install a variety of software and configuration of various environments, compared to green. In addition, it is convenient for me to share files among various virtual machines.
The idea of the program is simple, that is, the sender traverse the directory to be sent, send each file in turn. The receiver is a bit more complicated because of the problem of breaking packets and sticky packets, knowing the boundaries of each file, and maintaining the same relative directory structure as the sender.
My approach is to send a JSON data before each file is sent, to describe the relative path, file name, and file size of the file that will be sent next, so that you can handle the directory structure and boundary problems. But then you need to determine the bounds of the JSON data, so the length of the JSON data is sent before the JSON is sent, do you want to know the boundary of the data that describes the length? Of course, but the length of the unified UInt32, that is, a fixed 4 bytes is OK.
You need to be careful when receiving data, JSON length data, JSON content will have the problem of packet breaking and sticky, need to carefully determine.
The code is on GitHub, and the address is:
Https://github.com/Anti-Magic/share_sender
Https://github.com/Anti-Magic/share_receiver

In addition, if you share only a few files, you can also take advantage of HTTP download, but it is not suitable for bulk downloading a large number of files.
Re-paste the HTTP download code:

1 Package Main 2 3 " http " 4 5 Func Main () {6     H: = http. Fileserver (http. Dir (". " ))7     http. Listenandserve (": 7000", h)    8 }

Related Article

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.