I am trying to build some GO tools in my project. I first run
go get golang.org/x/tools/benchmark/parse
The folder/binary structure does appear correctly under
$GOPATH/src/golang.org/x/tools/benchmark/parse
I tried running: go build golang.org/x/tools/benchmark/parse
and
go install golang.org/x/tools/benchmark/parse
however the binaries still do not appear in my $GOPATH/bin
Any help is greatly appreciated!
You can't build benchmark/parse, but you can import it.
From Godoc for Tools:
Package parse provides support for parsing benchmark results as generated by 'go test -bench'.
sudorandom's comment is right, parse.go doesn't use package main, so it won't generate a binary, while you can use it within your own code with import "golang.org/x/tools/benchmark/parse".
Related
So,I recently started following a video tutorial and i am fairly new to golang and tried installing the forked version of bolt db using
$ go get go.etcd.io/bbolt/...
Note : I want to use this specific version
but i am getting an error which says
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd#latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'
I read a few GitHub issues which say that go get is deprecated so how do I resolve this ?
I also tried few other things such as
go install go.etcd.io/bbolt/...
Go modules are today's standard. Especially if you are new to Go; do not spend time on material that do not use (and teach) them.
Run go mod init yourproject
in your project repository root directory. This will create go.mod file.
Once you have that you can either:
import go.etcd.io/bbolt in source code and then run go mod tidy. Go tool will find and add module to your dependencies (go.mod file). This is described in Getting started tutorial.
run go get go.etcd.io/bbolt directly, that will update dependencies too.
Using Go Modules series explains workflow in detail and will be helpful when converting commands from an outdated material.
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.
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
I'm using the GOfax.IP which I can download and build with:
go get github.com/gonicus/gofaxip/...
This works without any problems.
Now I want to make a small change in the source code before compiling.
I know that I can use go get -d to only download the sources, but how would I start the build/compile part of got get after I finished my modifications?
Thanks.
I found the answer myself:
go install ...
This seems to do exactly the same as go get after downloading the sources.
go -h can help you:
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
build compile packages and dependencies
...
I'm trying to understand the idea behind package naming convention in Go. Most packages are installed and imported as something like:
import "github.com/howeyc/fsnotify"
I get the idea that package names should be unique, but I don't see the point of using the website github.com. Why not just use author/package? Like:
import "howeyc/fsnotify"
That's not likely to ever collide. Or some other "shorter" strategy? Is it because it "just works" with go get? Or is there some other reason?
You can use howeyc/fsnotify if you want to. When github.com/howeyc/fsnotify is used it's understood that the package is hosted on Github. Other repositories work as well.
The reason is it makes it easier to locate and install dependencies with go get. Otherwise you'd have to satisfy the dependencies manually. And since forking repos is quite common in the open-source world, you may have a modified version from the same author. So it helps to distinguish what your project depends on.
Download and install packages and dependencies
Usage:
go get [-d] [-fix] [-u] [build flags] [packages]
Get downloads and installs the packages named by the import paths,
along with their dependencies.
When checking out or updating a package, get looks for a branch or
tag that matches the locally installed version of Go. The most
important rule is that if the local installation is running version
"go1", get searches for a branch or tag named "go1". If no such
version exists it retrieves the most recent version of the package.
For more about specifying packages, see 'go help packages'.
For more about how 'go get' finds source code to download, see 'go help remote'.
The import path supports the go get command. Paths denoting remote repositories begin with the path to the code. Run the go help remote command for details.