what is the difference between Go get and Go download commands - go

could you explain what the following commands on go doing exactly
go get golang.org/dl/go.1.15.6
go1.15.6 download
when using go get what exactly happens on the background is it only downloading the go.1.15.6 and what go1.15.6 download doing exactly ?

The command go get golang.org/dl/go.1.15.6 is deprecated. Use go install golang.org/dl/go.1.15.6 instead.
The command go install golang.org/dl/go.1.15.6 downloads, builds and installs a program named go.1.15.6. This program does not include the Go installation. Read the go install documentation for more details.
The command go1.15.6 download runs the program installed in the previous step with the download argument. When run this way, the program downloads the associated version of Go. After downloading, the Go tool sub-commands for that version can be invoked using the go1.15.6 program. Read Managing Go installations for more details on the go1.xx.x command.
Note that there is not a go download sub-command. Download is a feature in the go1.xx.x commands.

Related

Difficulty installing go buffalo using go mod on windows

I am very new to golang. I am trying to work with the gomod. Trying to explore the go buffalo framework. But finding a bit of difficulty in installing that.
What I have done:
I saw that go get is nomore supported for buffalo and so switched to go modules.
Created a module by go mod init github.com/webbuffalotest
Fetched go get -v github.com/gobuffalo/buffalo (on the same directory where I have go.mod file)
Fetched go get -v github.com/mattn/go-sqlite3 (on the same directory where I have go.mod file)
go install github.com/gobuffalo/buffalo
I was expecting a buffalo.exe inside %GOPATH%/bin so that I can add it to my path but didn't find one.
My question is what's wrong? Is the exe not installed or it's somewhere else because of go mod. Any help will be highly appreciated.
I am using windows 10. I am not willing to install package managers as scoop or choco to install buffalo. Thanks for your patience :)
Edited:
Also tried setting set GO111MODULE=on but of no use.
Solved:
My bad, I should have used go install github.com/gobuffalo/buffalo/buffalo instead of go install github.com/gobuffalo/buffalo
github.com/gobuffalo/buffalo is a library; the corresponding binary is (aptly-named) github.com/gobuffalo/buffalo/buffalo.
The go install command you ran should have warned you about that, but didn't because go install used to also be used to cache compiled libraries (it no longer does that in module mode).
I've filed https://golang.org/issue/46912 to add a diagnostic.

How can I install a specific version of golint for use globally?

I'm trying to create a docker image for use in a build pipeline that has various tools pre-installed for building and testing go projects. One tool we need is golint but I'm struggling to see how to install a specific version of it. The reason I want to lock down the version is to avoid accidental / unwanted / unintended breakages at a later date.
For a start, looking here the versions are not exactly in an easy-to-type format.
Also when I try to use the following command
go get -u golang.org/x/lint/golint#v0.0.0-20181217174547-8f45f776aaf1
I get an error
go: cannot use path#version syntax in GOPATH mode
Googling has so far yielded very few relevant results...
Is what I'm trying to do possible? Many thanks!
You need to be in go module mode to get code of a specific version, since in addition to downloading the code, the version is recorded in the go module file.
The easiest way to do this would be to create an empty directory, run go mod init, which will create a go.mod file.
Then, you can run go get golang.org/x/lint/golint#v0.0.0-20181217174547-8f45f776aaf1, which will add golint at that version to your go.mod file. You can then run go install golang.org/x/lint/golint from within that directory, which will install golint at the version specified into your $GOBIN directory (which defaults to $GOPATH/bin).

Can't install any GoLang script in Linux

When I try to run any Go script it show me this error
I installed go lang step by step from this link
https://www.tecmint.com/install-go-in-linux/
When I setup go script like this
go get github.com/tomnomnom/waybackurls
I got error like this
github.com/tomnomnom/waybackurls
src/github.com/tomnomnom/waybackurls/main.go:191: u.Hostname undefined
(type *url.URL has no field or method Hostname)
If you are following the guide you linked by copy-pasting commands, you will have installed Go 1.7.3. The function url.Hostname() was added in Go 1.8.
I suggest completely ignoring that guide. Remove /usr/local/go, remove ~/go_projects and undo the path related stuff.
Instead, use the package manager of your OS to install Go.
Most likely, this means you should do either sudo apt install golang (for Ubuntu, Debian, ...) or sudo dnf install golang (Fedora, CentOS, ...).
That will give you the latest version that is supported by distro maintainer (which at the moment is probably 1.11 or 1.12, depending on your distro).
As an alternative to the packagemanager, download the latest version from https://golang.org/dl/.
This approach also gives you an installation that follows the Go ecosystem their conventions for paths (I'm not sure if ~/go_projects was ever a think, but it isn't today).

Issues installing a go program

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.

How to install "gotests" command?

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

Resources