I'm trying to use the docker package in one of my Go applications. I'm importing the package as import "github.com/dotcloud/docker" in my script. But when trying to build the dependencies, that is, when I run go get in my project directory, it says:
foo.go:9:2: no buildable Go source files in /home/neville/gocode/src/github.com/dotcloud/docker
Here, my GOPATH is set to /home/neville/gocode, so when doing go get, the package should get downloaded to /home/neville/gocode/pkg, instead of /home/neville/gocode/src. What am I missing here?
github.com/dotcloud/docker isn't a Go package, and that's why there are no source files in that directory.
Import the package you want directly, like so for the registry package:
import "github.com/dotcloud/docker/registry"
Also, go get does download into $GOPATH/src. The installed object files go in $GOPATH/pkg.
Related
I have a project, which doesn't use go.mod, and not follow the structure that project is under $GOPATH/src/.... It uses bazel and WORKSPACE file to manage depedencies.
I use gopls in neovim, and it could not resolve imports like import github.com/pkg/errors, so I am thinking to install the package one by one. However, go get needs to be with a go.mod file, and go install only works when installing a binary.
What option I have here? Thanks!
I am trying to import a local file into my main.go file and this tutorial (and other similar tutorials) says to run go install <path> in order to import that path as a package. This seems like a slow way to develop local packages because you would have to run go install <path> every time you want to see the changes in your local package.
Is there a faster way to import/update local packages? I am using gomon to auto-reload my code after updating it, so ideally, my code would auto-reload after updating a local package.
You should use go modules. The tutorial you mentioned appears to be older than the modules feature. In short: you can import a package, run go build, and any imported external package will automatically be downloaded for you as needed, no need to do a go get. Start here:
https://blog.golang.org/using-go-modules
https://github.com/golang/go/wiki/Modules
Right now, I have imported a package. In my case it is
import "crypto/ecdsa"
This package contains a file called ecdsa.go. I'd like to view it, however I don't know where to see it. I can't seem to find it in my working directory. Is the file hidden? Or is it installed globally by default?
This package is a part of the Go project. You can find it in your <go-root-path>/src directory.
You can find your "go root path" by running go env GOROOT.
Probable location of Go in linux is /usr/local/go
Go standard library packages are located in GOROOT/src.
For GOROOT, run
go env GOROOT
For example, for package import "crypto/ecdsa" file ecdsa.go on Linux,
$ go env GOROOT
/home/peter/go
$ ls /home/peter/go/src/crypto/ecdsa/ecdsa.go
/home/peter/go/src/crypto/ecdsa/ecdsa.go
$
go version go1.11.4 darwin/amd64
GOPATH has been unset but was previously set to $HOME/Development/go
Project path is under $HOME/code/
I’m able to successfully (no errors at least) install the go-sql-driver/mysql package using the command
go get github.com/go-sql-driver/mysql#v1
When I include a reference to that package in an import statement
import(
_ "github.com/go-sql-driver/mysql")
in my code I see the error
could not import github.com/go-sql-driver/mysql (can’t find import:
“github.com/go-sql-driver/mysql”)
I have run go mod init in my project root and it creates a go.mod file. When I run the go get command I see a require statement added to that file for the package. But it seems the files for the package get installed in the default $HOME/go directory (since I've unset GOPATH).
Should I be doing things differently so that my import statement can find the newly installed package? Using modules shouldn't all the packages be installed in the project path somewhere?
Should I be doing things differently so that my import statement can find the newly installed package?
No. With modules there is no need to install the packages upfront at all.
Using modules shouldn't all the packages be installed in the project path somewhere?
No. They get downloaded somewhere in some format and used from that location but they are not "installed" like in the old GOPATH variant of go get.
Show output of go env and what go mod vendor produces.
I'm pretty sure I was doing things wrong. I was able to resolve this after referencing the following closely the steps documented at golang modules wiki. The summary is that there is no need to "install" a package via 'go get'. Instead simply make sure your project is initialized to use modules using the 'go mod init' command and then include the package name in an import statement. The next build event will pull down the package and all its dependencies.
I have a project which is built in Node.js/Express.js. I want to start to rewrite this to go/iris framework. I don't want to re-factor everything into my $GOPATH and I want to keep it together my express / go / docker files for this project.
I tried to clone iris framework's git repo into a ./vendor subfolder, but using import "github.com/kataras/iris" importing nothing.
Is there a package manager which is
copying and installing packages and all of it's dependencies in my-project/vendor folder outside $GOPATH
it can update these import packages
go run/build/install outside $GOPATH
there's now any new files in $GOPATH src/pkg/bin folder when I working on a project, except this package manager
I can define dependency packages for a project like package.json file for node.js
Is there a go package manager like that?
Edit:
Running this with go command is not required.
Not possible with the current go tooling, but looks like we might get it in go 1.12 or bit later.
Proposal accepted:
cmd/go: modify the Go toolchain to work without GOPATH