packages ecosystem? I've watched official google dev channel video about it, it's cool, but too ideal and simple example. In the real world i've faced much worse projects.
So, more specific questions:
- What is Go package (binary or/and source)?
- What is "main" Go package manager? (like npm in js)
- Why do we have such paths of packages "***/githubrepopath/**"? I understand, that it's not obligatory, but why i got such structure in the hello world example?
- dependency resolving
- package structure
Thanks a lot. It seems "easy", but i keep getting that feel i don't get what the hell is going on and how i can handle it easily.
1) bin is the place where binaries are put ($GOPATH/bin is in your env variable as well). Src is the place where your source code is located (the same for all the dependencies) 2) go get, but other ones are being made as well like godep 3) go get uses git repositories and it’s just a path from $GOPATH/src (or a vendor folder). When getting a dependency the location will be: gitserver/username/projectname
There is no "main" package manager in go. There are 2 official package managers, vgo and dep. vgo is nicer and it'll remove the need for GOPATH. Then there is also go mod, I have no idea when it was built but it's pretty cool. https://dave.cheney.net/2018/07/14/taking-go-modules-for-a-spin As for, Dependency resolution, The compiler frontend first checks the dependency in $GOROOT and then in $GOPATH. GOROOT is where the compiler installed all its files, And GOPATH is set by the user. You can set it to a different directory for each project or you can just use one common GOPATH for everything. The structure of GOPATH is this, /(GOPATH) - -> pkg -- -> src - - > bin pkg folder contains compiled libraries that help in quickly compiling a project. bin contains executables. A lot of people add $GOPATH/bin to their $PATH. So, lets say if you have a project in $GOPATH/src/xyz, You can go in this directory, Run go install which will create an executable and put it in $GOPATH/bin. Since, $GOPATH/bin was in $PATH, You can use the command xyz anywhere you like. src folder contains the source code of all the libs you have downloaded. As for why the import paths contain, github.com/blablabla, I guess, go get tool was designed to pull the dependecy and put it in $GOPATH/src but there might be a situation when you have two different projects with the same name and that wouldn't work, So they changed it to create subdirectories. Go doesn't supports relative import paths, So, You need to use absolute import paths but the root is at $GOPATH/src. So, To import a package, You only need to write import github.com/xyz/abc instead of the complete absolute path to folder abc on your machine.
Обсуждают сегодня