It is not clear for me from Golang tutorial how to put Golang code to Github to be able to import that code as a package from Github later.
This is an example project-workspace (directory structure) from the Golang tutorial http://golang.org/doc/code.html:
bin/
hello # command executable
pkg/
linux_amd64/ # this will reflect your OS and architecture
github.com/user/
newmath.a # package object
src/
github.com/user/
hello/
hello.go # command source
newmath/
sqrt.go # package source
So, what do I need to do, where do I need to git init
in this workspace, to be able later:
-
To import only
newmath
package into my some separate project. This way:import "github.com/user/newmath"
-
To get only
hello.exe
executable. -
To get the whole project-workspace (all directories: bin, pkg, src).
Best Answer
For the package
newmath
it's the same as (later 2.)Now people can do
and
import "github.com/username/newmath"
should now work in their sources. The package will be installed on demand automatically.
I'll assume that the
hello
command and thenewmath
package are not related, or not enough tightly related to belong to a single repository.Now people can do
to install your command
hello
.$GOPATH/pkg
at the hosting service.$GOPATH/bin
at the hosting service. But I discourage this practice for obvious reasons. Additionally, if you're publishing the sources - the binaries are not necessary and everybody can build their (trusted) own.You seem to be perhaps still a bit confused by the term 'workspace'. A workspace is quite often existing only once at the developer's machine, yet it the typically contains several repositories. Some authored by the developer, others "go getted" from the Internet. To publish a whole wokspace in this case makes little sense.
However, there are people using a separate workspace per project or per repository or maybe even per package. I don't know what the benefits are. Or better said, I think that there are none compared to the single workspace, defined by, say
export GOPATH=$HOME
(as is my case for years w/o any trouble with it for years).