Recently, I switched to go language server. The boss wrote a very complex framework without documentation. When reading the source code, I was very painful. I didn’t have a good memory and couldn’t remember anything, so I came up with a way to create UML class diagram through the source code. C + + and java have similar tools and software, but the go language can only be developed through an open source project on GitHub.
I met many pits in the middle, so I almost wrote down this article.
First of all, according to the online articles, the first step in this project is to go get *****************************************************************
Here is the error list:
package git.oschina.net/jscode/go-package-plantuml: unrecognized import path "git.oschina.net/jscode/go-package-plantuml" (parse https://git.oschina.net/jscode/go-package-plantuml?go-get=1: no go-import meta tags (meta tag gitee.com/jscode/go-package-plantuml did not match import path git.oschina.net/jscode/ go-package-plantuml)) package gitee.com/jscode/go-package-plantuml.git: cannot download, git://gitee.com/jscode/go-package-plantuml uses insecure protocol package https:/gitee.com/jscode/go-package-plantuml.git: https:/gitee.com/jscode/go-package-plantuml.git: invalid import path: malformed import path "https:/gitee.com/jscode/go-package-plantuml.git": invalid char ': go: missing Git command. See https://golang.org/s/gogetcmd
Then the Internet is poor in all kinds of data, which still can’t be solved.
Later, after reading a blog, the boss used git clone (in fact, I thought about using git clone before, but I got stuck in the subsequent compilation error, which made me think that the items obtained by go get were specially processed). The boss said: in fact, go get and git clone actually do the same thing, g the only special processing done by the former is that the storage path is different.
As for what path it is, I’m not very clear. Well, the boss gave me this Ke reassurance. I got the project git clone down, and then it got stuck in the compilation.
Here is one of the errors I encountered:
Many other mistakes I asked me to clear the screen, leaving such a one. In fact, most of my mistakes are that the three environment variables of go language are not aligned. Gopath, goroot, and path environment variables.
Gopath can be regarded as the storage path (i.e. working path) of the project. I don’t know if my understanding is correct. If it is not correct, who understands? Please point out my error, but it seems that the project can work normally
Goroot is the installation directory of go language. It can only be set to *: / go, and * represents the drive letter. However, I don’t know how to change it to go / bin. As a result, the command line prompts that I can’t find the project during compilation, and then the error path is very strange. There are two bins in it, that is, the path becomes * * / bin / bin / * * *, which is strange to find.
Path is the system environment variable. You need to add / bin to goroot.
Then, when mutating, it still reports an error, saying that the project cannot find the required package or file under the specified path. In fact, this still involves the path problem.
My solution is to copy all the packages that can’t find the path to the * / go / SRC / directory, and then modify the error code line. However, even if this is the case, some files can’t be found. I think of modifying the import path and directly changing it to a relative path.
In this way, my project was finally compiled successfully. Some codes in the relative path may not work well. The boss said that it is recommended to put them in the SRC directory under the working path or in the SRC folder under the go installation directory.
Correction: be careful not to use relative paths, otherwise the compiled exe will appear during execution
Later, I found that I added the directory many times in one fell swoop. The reason why the compilation of the original project is wrong is that I didn’t configure the project path at all (I didn’t mention adding the project path to gopath). After configuring the gopath path path of the project, the direct compilation can succeed.
Moreover, if you do not configure the project path to gopath, you only solve the compilation error as in my first method, and an error will be reported at runtime (this is a sad story. I have started to animate the UML class diagram in Golan). The UML file cannot be generated. The command line prompts that the generation is successful, but the generated file cannot be found under the path, Because in fact, there is no generation, and the path is not configured
Supplement: cannot resolve directory ‘GitHub. Com’ appears when the go language uses golang to import GitHub projects
In the process of learning go language, I downloaded several projects from GitHub, but the whole article reported red with golang. Gopath repeatedly checked that there was no wrong setting. I searched all kinds of methods, and finally solved the problem and recorded it.
terms of settlement
Remove the tick in the figure in the settings of golang
The reason is that the item in the GoLand editor is set to go modules, which leads to reading from gomod, resulting in an error. Remove the tick, and the problem is solved perfectly.