I install godef:
$ go get -u github.com/rogpeppe/godef
Looks great:
$ which godef
/home/username/go/bin/godef
Right where I expect it:
$ echo $GOPATH
/home/username/go
But when called as a command line tool:
$ godef version
godef: cannot read : open : no such file or directory
What's happening?
I would suggest you to read the documentation found here: https://github.com/rogpeppe/godef/blob/master/doc.go
You can also try typing godef -h.
If you want more information, please explain what you are actually trying to do.
EDIT: Regarding your comment above, I think that this library can't help you to accomplish what you are trying to do.
I ran into an issue trying to use godef-describe (C-c C-d) which would output the following error:
No description found for expression at point
If I tried using godef directly on a file, I would receive the following error:
% godef -f path/to/file.go "SomeFunction()"
2020/08/26 14:57:46 internal error: nil Pkg importing "io" from "github.com/some/package"
I fixed this by reinstalling godef and using the master branch as described here:
go get -v github.com/rogpeppe/godef#master
since the latest updates on go and go.mod you might want to install it on your user so you should use install instead of get
if you want to install godef to your gopath:
go install -v github.com/rogpeppe/godef#master
Related
I'm trying to install my package using go install but I get this error message when running the command go install github.com/JoaoDanielRufino/gcloc/cmd/gcloc#latest:
go install: github.com/JoaoDanielRufino/gcloc/cmd/gcloc#latest: module github.com/JoaoDanielRufino/gcloc#latest found (v1.0.0), but does not contain package github.com/JoaoDanielRufino/gcloc/cmd/gcloc
I want the executable name to be gcloc.
Here is the current source code: https://github.com/JoaoDanielRufino/gcloc
Note: I've already tried go clean -modcache but it didn't work
As the main function of this package isn't on its root, you should pass the directory of the main package on your command.
So, your command will be:
go install -v github.com/JoaoDanielRufino/gcloc/cmd#latest
I came across a similar issue when I was trying to use go install to install the cloudflare/cf-terraforming tool on my machine. The documentation for this tool is not clear on the installation and I had to dig around to get this to work
Basically #Jictyvoo answer above sums it up, if the path is pointing to anything other than directory where the main.go file is sitting I got the error
Command: go install github.com/cloudflare/cf-terraforming#latest v0.8.0#latest
go: github.com/cloudflare/cf-terraforming#latest: module
github.com/cloudflare/cf-terraforming#latest found (v0.8.0), but does not
contain package github.com/cloudflare/cf-terraforming
when I switched to the below it worked fine for me:
Command: go install -v github.com/cloudflare/cf-terraforming/cmd/cf-terraforming#latest
This worked for me after checking the repo and realising that the main.go file was sitting in the cmd/cf-terraforming subdirectory
godoc command doesn't work on my system (I'using Linux Mint 20 Ulyana).
I've just tried this procedure:
install godoc with following command:
go get golang.org/x/tools/cmd/godoc
Start godoc server:
godoc -http=:6060
The result is:
bash: godoc: command not found
I'm using this go version go version go1.15 linux/amd64
And this is my PATH variable /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/go/bin
All other go commands (go build, go run and so on) work correctly.
What can I do to make godoc command work?
I have a different issue. As of 1.18, you must now run
go install golang.org/x/tools/cmd/godoc
This is because go get is deprecated for
Starting in Go 1.17, installing executables with go get is deprecated. go install may be used instead. In Go 1.18, go get will no longer build packages...
In other words, go get in 1.18 and beyond will no longer install executables. Use go install.
Step - 1: Check if godoc package is installed
Make sure you can run godoc using this command:
$GOPATH/bin/godoc -http=:6060
Step - 2: Install godoc package
If you don't see any error then go to Step - 4 else if you can see this error No such file or directory then you have to get the godoc package first by using this command:
go get golang.org/x/tools/cmd/godoc
It will take some time to install.
Step - 3: Try godoc command
Try this command
godoc --help
if this command ran successfully then you are done and nothing else to do else if you are still getting any errors follow the Step - 4 and if you still fail please check if you have defined the $GOPATH variable correctly
Step - 4: Add path variable
Add $GOPATH/bin to your PATH variable by using this command:
export PATH="$GOPATH/bin:$PATH"
Try Step - 3 now.
Add $GOPATH/bin to your PATH variable. Executables, like godoc, are installed to $GOPATH/bin.
export PATH="$GOPATH/bin:$PATH"
godoc -http=:6060
Below is what I did on macos, it should work on linux as well.
Add this to your ~/.bashrc or ~/.zshrc:
export GOPATH=$HOME/go # or somewhere else
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
Reload your terminal and run:
mkdir -p $GOPATH $GOPATH/src $GOPATH/pkg $GOPATH/bin
go install golang.org/x/tools/cmd/godoc#latest
godoc -http=localhost:6060
Then you can open your browser at localhost:6060 to RTFM ;-)
I'm using macOS, for me $GOPATH was not configured and the path I found the installed package was $HOME/go/bin/godoc. Check out go help gopath for more information regarding this.
I've installed these packages:
google.golang.org/grpc
github.com/golang/protobuf/protoc-gen-go
and exported path like this:
export PATH=$PATH:/usr/local/go/bin
when I try compile proto file with protoc command, I see command not found error:
protoc --go_out=. helloworld/helloworld.proto
zsh: command not found: protoc
my project path is like: /home/my-username/go/src/github.com/my-username/helloworld
my go version: go1.12.5
and I use ubuntu 18.04
When I install it with binary file it works, but compiled go file does not contain some functions like: RegisterGreeterServer or NewGreeterClient
zsh: command not found: protoc indicates that protoc is not installed on your machine. To do so, you need to download binary from Official Releases, as you are on an ubuntu machine, I suggest you download protoc-3.7.1-linux-x86_64.zip (This is latest protoc at the time of writing this answer, you should check on the releases and download latest version)
You can download via browser or use following command:
wget "https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/protoc-3.7.1-linux-x86_64.zip" -O protoc-3.7.1-linux-x86_64.zip
Now unzip, you'll get two folders, "bin" and "include".
Copy bin/protoc to /usr/local/bin/protoc and include/google to /usr/local/include/google
This will properly install protoc on your machine.
To see if it got installed properly, try executing protoc command on your terminal. You should get something like following
If you still face any issues, please let me know.
Hope this helps!
Finally with help of Amit, I installed protoc. but when I compiled proto file with this command
protoc --go_out=. add/add.proto
go compiled file did not contain some functions like: RegisterGreeterServer or NewGreeterClient for instance.
by this reply I found out issue and added plugins=grpc, then tried this command and it worked:
protoc --go_out=plugins=grpc:. add/add.proto
I know its too late to discuss about it, but just in case it might be helpful for some one else, you can download protobuf for golang from github address Github Repo
and by navigating to {$LIB_PATH}/protobuf/protoc-gen-go and running "go build ." having a compiled binary from generator, and then add it to your path for feature usage
Im new to go and I have been unable to find any thing online for my issue.
I have downloaded this code https://github.com/hashicorp/http-echo and I would like to set it up so I can run this command.
$ http-echo -listen=:8080 -text="hello world"
I have been getting quite a few different path issues.
Currently I have the code sitting in this directory.
/Users/jon/go/src/github.com/hashicorp
When I try and install it I get this error
$ go install http-echo
can't load package: /usr/local/go/src/http-echo/handlers.go:9:2: non-standard import "github.com/hashicorp/http-echo/version" in standard package "http-echo"
Where should I keep go projects on an OSX computer, and how do I get this to install or compile?
The code currently seems to be in /usr/local/go/src/http-echo. Packages should always reside in the directory $GOPATH/src/package-name, e.g.: $GOPATH/src/github.com/hashicorp/http-echo. (unless you're using go modules).
It should work if you move the source to the correct path (/Users/jon/go/src/github.com/hashicorp/http-echo). Then execute:
go install github.com/hashicorp/http-echo
Even easier would be to use go get to download the package in the first place. Simply run the following command from any directory:
go get github.com/hashicorp/http-echo
And http-echo is automagically installed.
If you still get an error after this, make sure $GOPATH/bin is in your $PATH.
I need to use the test driven development in Go using "gotests" command.
gotests -all *
This is not working. I did go get -u /github.com/cweill/gotests
and go install. But there is no binary created in $GOPATH/bin.
since there is NO main package, Use this command
$ go get github.com/cweill/gotests/...
this itself download all dependencies for the current package, and creates bin file, after downloading this package. see in $GOPATH/bin there will be a bin file named gotests
for more see HERE
The following worked for me with go v1.19.1
go install github.com/cweill/gotests/gotests#latest
Using go get to install things has been disabled since 1.18. See Deprecation of 'go get' for installing executables
go install github.com/rakyll/gotest
Source: https://github.com/rakyll/gotest