Golang Guide Bag

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

By the pit of the pieces, hereby commemorate, not novice don't look

Package structure

Next we're going to call the methods in Myprint2.go in Main.go.

Myprint2.go

Package Testimport "FMT" func MyPrint2 () {fmt. PRINTLN ("This message comes from Myprint2")}

Myprint.go

Package Testimport "FMT" func Myprint () {fmt. PRINTLN ("This message comes from Myprint")}

Main.go

Package Mainimport ("Try2/test") func main () {test. MyPrint2 ()}


Output results

C:/go/bin/go.exe Build-i [E:/goworkspace/src/try2] Success: Process exit code 0.e:/goworkspace/src/try2/try2.exe  [E:/ GOWORKSPACE/SRC/TRY2] This message comes from Myprint2 success: Process exit code 0.

Next, let's talk about the pit here:

1 package is a bag, really is a package, is the special folder Ah, the physical folder Ah, lying trough ah, pit daddy Ah, I first write when Myprint.go and Myprint2.go package is not the same (don't ask why, I do not know what to think, in order not to mislead everyone, do not write it out) , the result main.go call of time, various error;

2 when imported, the import is also a package, this "package" with the above package meaning, but with the Java contains the semantics is not the same, if you do not know the preceding sentence what the meaning, do not go to search, the more you do not want to remember the more difficult to forget things;

3 Call, use the package name. Method name to invoke, but, however, I did not try the structure, why did not try, I am lazy. If anyone sees this place and tries it yourself, please let me know. If anyone sees this place and wants to know it, remember to tell me after the answer. I'm lazy.



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.