Go Tool: Difference between revisions
(→run) |
|||
Line 47: | Line 47: | ||
go clean -cache | go clean -cache | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===<tt> | ===<tt>-fuzzcache</tt>=== | ||
Clean the [[Go_Build_Cache#Fuzz_Cache|fuzz cache]]: | Clean the [[Go_Build_Cache#Fuzz_Cache|fuzz cache]]: | ||
<syntaxhighlight lang='go'> | <syntaxhighlight lang='go'> |
Revision as of 01:19, 14 September 2023
External
Internal
Overview
go
is a command line tool with multiple uses: package manager, build tool and test driver. go
manage packages in workspaces, query metadata about packages, print documentation, build, format, download, test, etc.
Commands
Help
go help <command>
go help build
build
The build
command compiles one or more packages and builds the executable if the package main
is among the compiled packages. The tool is sensitive to GOPATH mode. For more details, see:
TO DEPLETE Go_Commands_-_build.
Build Flags
-a
Force rebuilding of packages that are already up-to-date.
-n
Print commands but do not run them.
-x
Print the commands while running them.
-v
Print the names of packages as they are compiled.
-work
Print the name of the temporary work directory and do not delete it when exiting.
install
go install
can be used to:
go install
compiles the package or module code, as described in the respective sections. If the package is main
or the module contains a main
package, an executable is linked and installed under the directory designated by the GOBIN environment variable. If there is no main
package, the package object files (one or more per package? research) is stored under pkg
.
The build flags specified above apply.
run
The run
command compiles the specified packages or files by delegating to go build
and then runs the executable. There must be a main
for an executable to be generated.
cd $PROJECT_DIR
go run ./src/main/main.go some-arg-1 some-arg-2
The first argument that does not end in .go
is assumed to be the beginning of the list of command line arguments of the executable.
clean
-cache
Clean the build cache:
go clean -cache
-fuzzcache
Clean the fuzz cache:
go clean -fuzzcache
doc
The doc
command prints documentation for a package or a package member:
go doc time
go doc time.Since
fmt
The fmt
("format") command formats source code files.
get
The get
command downloads packages and installs them.
list
The list
command lists all installed packages.
test
The test
command runs tests. For more details, see:
env
The env
command prints the effective values of the environment variables relevant to the tool chain.
go env GOOS GOARCH GOPATH
get
The get
command retrieve and update packages.
TODO Addison-Wesley The Go Programming Language Section 10.7.2
mod
Initialize a v0 or v1 module:
go mod init example.com/m
Initialize a v2 module:
go mod init example.com/m/v2
Inspect the code, look for module imports, download them and update go.mod
.
go mod tidy
TO DEPLETE
Deplete: