Simple project with examples and experiments around the Go language.
- Check .tool-versions for the Golang used version.
- Run main with
go run .
or build an executable withgo build
(dependencies are downloaded automatically) - To install dependencies declared in go.mod explicitly use
go mod download
.
To start a new project in Go
- Create a new module
go mod init <module>
- Module name by conventions is
<host>/<user>/<module>
- Where host is github.com, user or company that manages the module and finally module name.
- This will create a go.mod file with the module name and the Go version used. It will also contain dependencies and their versions
- Module name by conventions is
- Every module needs a main package and a main function which will be the entry point (file doesn't need to be called main.go)
- To add a dependency, use
go get <module>
it will be added to the go.mod file and the go.sum file (which contains the checksum for integrity check) - Only methods and variables starting with upper case can be used from other modules
Other useful commands:
go mod tidy
to remove unused dependencies or add missing ones.go mod vendor
to create a vendor folder with all the dependencies.go install
downloads and install a package. It will be available in $GOPATH/bingofmt -w .
format