Recently, I downloaded a project named Blue Eye Cloud Disk for my study and research purpose. This is an open source server – side development in go language project.
I’ve never used GO, so THERE are low-level problems to solve. GOPATH is divided into global GOPATH and project GOPATH. 3. Download dependent packages. 4
I installed the GO locale, opened the project using the JetBrains GoLand development tool, and then “Run”, an error was reported. The error is located in the main function main.go.
import ( "fmt" _ "github.com/go-sql-driver/mysql" <! -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - "log" here ".net/HTTP "" tank/rest" <! -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- here)Copy the code
Just say you can’t find the relevant bag.
I don’t know exactly why, like,”Github.com/go-sql-driv…
So according to the information on the Internet, little by little Settings.
GOPATH is a system environment variable. I didn’t mention this when I installed the GO environment, but it didn’t seem to bother me that I could output “Hello World” normally.
hello.go
package main import "fmt" func main() { fmt.Println("Hello World! \r\n Hello, leftFist!" ); fmt.Println("Hello Human!" ); if(3 > 4){ fmt.Println("3 > 4"); } else { fmt.Println("3 <= 4"); }}Copy the code
This GOPATH is similar to the Eclipse WorkSpace, pointing to the grandfather folder where the source code resides. The source code is placed under: %GOPATH%/ SRC /. For example, if the blue eye cloud disk project is in a folder named “tank”, it will be located in the following location: %GOPATH%/ SRC /tank. Why do you have to put it in “SRC”? Maybe that’s the rule of GO, convention over configuration.
2. GOPATH is divided into global GOPATH and project GOPATH
As mentioned above, GOPATH points to the source folder, but it seems inappropriate to have all the GO projects in one place. In fact, GOPATH can be divided into global GOPATH and project GOPATH, which can point to different folders.
In this way, some public packs can be stored in the global GOPATH, while private packs can only be stored in the project GOPATH.
I looked for the command to download the dependency package in Goland and could not find it. You can only download it manually. Under %GOPATH%/ SRC, go to CMD and type something like the following:
go get github.com/go-sql-driver/mysql
Copy the code
This can also be done directly from GoLand’s command line window
4. Set the project output folder
After downloading the dependency package, it compiles, but does not run correctly. The reason is that the project needs to read a configuration file. This is the logic of the project itself, independent of the GO environment. This configuration file is in a [/build/conf] folder. It looks like an error occurred when the project was run and the root directory could not find it.
Solve this problem by setting up goland’s project configuration.
Change the Run kind type to package and set output directory to build. Run is ready.
Those are some of the operational details. Not even technical details, just operational details, whose only value is to avoid forgetting.