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.