I have just started learning GO development, read a lot of articles and documentation, however haven't found a concrete answer.
There are some questions
./../
doesn't work, I can put all my source code under vendror/src
directory, but it makes my project structure to look not like I wantI know that this question has been already asked several times, however I haven't found any complete answer.
I would be grateful for any help. Thanks
your import path must be valid in $GOPATH/libPath
syntax
for that you can share your services source code as much as you want and just seprate bin by using multiple main package
if you mean directory by second files, there is no best practice for that, as long as it doesnt concern your code complexity, you can do that too
First: Read "How to Write Go Code" and stick to it and only to it.
There are no "local packages" for the go tool. Forget that distinction of local, non-local, remote, whatever. For the go tool there are just packages and these packages have an import path. This import path determines where the go tool will look for the code in the filesystem. If your import path is import "int.microsoft/secret/new/foo"
then your code for package foo must be located on your machine under `$GOPATH/src/int.microsoft/secret/new/foo".
For go build
and (go install, go test, ...) there is no meaning in the import path at all: "int.microsoft/secret/new/foo" is no other string than "example1/foo" or "github.com/someone/tool7/bar". These are just strings and the packages are searched in these paths. None of these packages is a "local" package, they all are just packages.
So if you put your code for package "whatever" under $GOPATH/src/some/strange/path/whatever you have to import it like import "some/strange/path/whatever"
.
If you want to share your code with someone else, keep a remote backup or want to use a codehosting site like github to simplify synchronizing your three workstations you can upload your code to e.g. github. This is unrelated to how you import your packages.
The only subcommand in the go tool where import path do have an additional meaning other than being a path is for go get
which knows about a few code hosting sites like github and interpretes an import path of "github.com/someone/prjct" and can clone this git repo for your, conveniently placing it in the right folder under your $GOPATH.
So: No. There is absolutely no need to upload each and every bit of code. (E.g. I have a lot of stuff just on my machine under $GOPATH/src/tmp).
Splitting code into a) different packages and b different files is unrelated to all this. Just do as you find convenient and logical.
Well, no; simpliy because you cannot keep several files in one file. Did you mean "several files in one folder"? Yes that is fine. Split into files and packages if the split makes sense. Take a look at the standard library or any other open source project.