In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What this article shares to you is about the example analysis of GO import package reporting errors and GoLand setting GOPATH, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Go, write while trying, in the import package that part, need to pay attention to a lot of small points, here is a summary.
First of all, give a successful case of my practice, and then summarize the points for attention.
Go version go1.16.2 darwin/amd64
Directory structure
Main.go
Package mainimport testPackage "test" func main () {testPackage.Test ()}
TestPackage.go
Package testPackageimport "fmt" func Test () {fmt.Println ("test_success")}
My GOPATH is set to the go_practice level.
With regard to GOPATH, I refer to this article. Http://c.biancheng.net/view/88.html
Quick View can use commands (macOS and linux)
Go env | grep GOPATH
I used GoLand, so I didn't modify env. GoLand can directly set the GOPATH of the current project, supporting multiple.
You can set the global and the current project respectively.
In addition to GOPATH, you need to note that:
After import, what is in double quotes is actually the name of the folder where the package is located (you can refer directly to the folder under src under the GOPATH directory), rather than the package name defined in the file (package testPackage).
The name before the double quotation mark is a custom name, and it doesn't have to be a package name. For example, I can also succeed if I change the main file to "":
Package mainimport "test" func main () {.Test ()}
So in fact, the package name defined by package in the file only needs to be consistent for all files in the same folder, and the package name and folder name are not required to be unified.
However, it is more convenient to unify it, and you can call the method directly through the package name, eliminating the need for an alias.
Package mainimport "test" func main () {test.Test ()} package testimport "fmt" func Test () {fmt.Println ("test_success")}
In addition, GoLand can be completed automatically. Like this
The first letter of the function name of the imported package is capitalized before it can be called externally (public declaration).
The above is the example analysis of GO import package reporting errors and GoLand setting GOPATH. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.