Questions tagged [go-toolchain]

The Go toolchain is an umbrella term that refers to the Go CLI and its commands, as go run, go build, go test, and so on. Use this tag for questions related to the usage of these commands. For questions specifically related to the go mod command, you may also use [go-modules] tag.

The Go toolchain is the set of commands supported by the go command line interface. It is developed and maintained as part of the Go programming language itself, and is part of the official Go distribution.

The full documentation can be found here: https://pkg.go.dev/cmd/go.

Some of the most frequently used commands are:

  • go get to fetch, update and/or install dependencies
  • go build to compile Go programs and build binaries
  • go test to run unit tests
  • go mod to initialize, organize and maintain Go modules
  • go vet to run static analysis
24 questions
228
votes
4 answers

How can I install a package with go get?

I want to install packages from github to my $GOPATH, I have tried this: go get github.com:capotej/groupcache-db-experiment.git the repository is here.
roger
  • 9,063
  • 20
  • 72
  • 119
14
votes
3 answers

Why does the "go run" command fail to find a second file in the main package?

I am experiencing an issue where go run main.go produces the error: # command-line-arguments ./main.go:9: undefined: test However the commands go build && ./goruntest compile and run the program just fine. The output is: Hi from test() Hi from…
robbmj
  • 16,085
  • 8
  • 38
  • 63
12
votes
2 answers

Go file not running which is not in main package

I have a very simple Go project setup. At root directory I have go.mod file and main.go and a folder called main2. Inside main2 folder there is main2.go file. / |_ go.mod |_ main.go |_ main2 |_ main2.go From root directory I am trying to run go…
mohit singla
  • 151
  • 1
  • 1
  • 7
6
votes
3 answers

goimports needs to ignore vendor package

I am trying to implement dep in my project. This is all working well but it also adds a vendor directory. I now need to update my tooling to ignore this directory or my vendored packages will be modified or I get false positives of warnings. I am…
snorberhuis
  • 3,108
  • 2
  • 22
  • 29
5
votes
1 answer

How to find the declaration of an Ident using go/analysis?

I use go/analysis to create my own static analysis tool. I still don't know how to find the def information from ast.Ident. Here is my testdata package randomcheck func xxx() { } func demo() { xxx() } And my own analyzer import ( "fmt" …
5
votes
1 answer

With "go list" how to list only Go modules used in the binary?

I want to list the modules (and their versions) that are compiled in the final executable (and not other dependencies). I can do that with: $ go build -o a.out $ go version -m a.out But how can I do that with go list (which has a convenient JSON…
dolmen
  • 8,126
  • 5
  • 40
  • 42
5
votes
2 answers

Programmatic way to call go tools

Is there a way to call the Go tools (like go build) programmatically from within another Go program with a library call and to get more structured output compared to the text output from the command line invocation?
anselm
  • 842
  • 2
  • 9
  • 22
4
votes
0 answers

Go vet is telling me I'm copying a lock, when I don't think I am

You can find the code I'm working on at: https://github.com/bigblind/marvin gometalinter is giving me the following error from go vet: accounts/interactors/accounts_test.go:16::error: literal copies lock value from ma:…
bigblind
  • 12,539
  • 14
  • 68
  • 123
2
votes
1 answer

How to determine the tree of files which are imported during a test case?

When I run a test in Go, is there any way for me to get the list of files that the code imports, directly or indirectly? For example, this could help me rule out changes from certain parts of the codebase when debugging a failing…
shmth
  • 458
  • 3
  • 11
2
votes
1 answer

How to retrieve parent node from child node in golang ast traversal?

Here is test file func demo() { name:=xxx() fmt.Println(name) } And my ast traversal code ast.Inspect(f, func(node ast.Node) bool { assign, ok := node.(*ast.AssignStmt) // find -> name:=xxx() if !ok { return true } …
1
vote
0 answers

Extract object files from the archive that is generated by the Go compiler

I would like to analyse Go object files. When I use the following command: go tool compile -o test.o test.go the generated file test.o is in the form of an archive (known as Go object archive). I can extract it using go tool pack x test.o which…
1
vote
2 answers

How To Download Client-Go V12.0.0 via Go Get Cmd Tool

when I execute below cmd: go get k8s.io/client-go@v12.0.0 it tells me: "go: k8s.io/client-go@v12.0.0: invalid version: module contains a go.mod file, so module path must match major version ("k8s.io/client-go/v12")" ok, then I changed the cmd to…
Wallace
  • 561
  • 2
  • 21
  • 54
1
vote
0 answers

Static URL that always links to the latest Go binaries?

I am writing some build scripts for packaging some software for a Linux distribution. Inconveniently, this software requires a very recent Go version that's not available in the distribution's repositories. Therefore, I have resorted to directly…
cyqsimon
  • 2,752
  • 2
  • 17
  • 38
1
vote
0 answers

How can I manually use go tool compile to compile multiple packages into a single executable file

For some reasons I need to use "go tool compile" to compile go files instead of using the automatic go build. "go tool compile" works fine with one file or multiple files in the same package, but if my project structure is…
ddaa
  • 49
  • 2
1
vote
2 answers

Using custom linker script with Go build

Is it possible to use custom linker script (.ldscript) as the Go executable generated from go build command is not supported on my target environment as it expects the sections to be in different order ? I checked the go tool link -extld option, but…
0xFFFFFFF0
  • 65
  • 5
1
2