Go: Difference between revisions
Appearance
NickPGSmith (talk | contribs) Created page with "== Notes ==" |
NickPGSmith (talk | contribs) No edit summary |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== | == Building and Packages == | ||
go run test.go | |||
go build test.go | |||
If there are multiple files in the main package, must make go access all of them: | |||
go run . | |||
go build . | |||
To remove debug symbols: | |||
go build -ldflags="-s -w" . | |||
In multi-file projects, main.go is the convention. The binary name is taken from the project directory. | |||
gofmt -w . | |||
gofmt -d test.go | |||
Initialise project, create go.mod file: | |||
go mod init example-project | |||
Download, and add reference to go.mod file: | |||
go get github.com/alexflint/go-arg | |||
Ensure go.mod is in sync with code imports: | |||
go mod tidy | |||
Note the go.sum file that contains anti-tampering checksums. | |||
=== Useful Packages === | |||
* [https://github.com/alexflint/go-arg alexflint/go-arg] | |||
* ? | |||
Latest revision as of 07:18, 24 January 2026
Building and Packages
go run test.go go build test.go
If there are multiple files in the main package, must make go access all of them:
go run . go build .
To remove debug symbols:
go build -ldflags="-s -w" .
In multi-file projects, main.go is the convention. The binary name is taken from the project directory.
gofmt -w . gofmt -d test.go
Initialise project, create go.mod file:
go mod init example-project
Download, and add reference to go.mod file:
go get github.com/alexflint/go-arg
Ensure go.mod is in sync with code imports:
go mod tidy
Note the go.sum file that contains anti-tampering checksums.