Time continues to run out.
I’ve been researching file I/O in golang, and noticed that Go 1.16 introduced a new module to do things like traverse FS directories, but I’m using 1.15.
You can manage multiple go installations using go
itself.
You just need to make sure things are set up properly.
It is, yeah?
# check your current version of go
# $ go version go1.15.2 darwin/amd64
go version
# check where this go is
# $ /usr/local/go/bin/go
which go
# check that your go env variables are all set
# $ GOBIN=""
# $ GOROOT="/usr/local/go"
# $ GOPATH="/Users/hgpa/go"
go env
# install the latest version
# NOTE: versions > 1.15 use `go install` instead
go get golang.org/dl/go1.19.2
Uh, what were those for again?
GOROOT
is where Go SDK is installed.
GOPATH
is the root of your Go workspace.
In the past you had to develop your go app in this path.
GOBIN
is where binary you install live.
# ~/.zshrc
# configure golang
export GOPATH="$HOME/go"
export GOBIN="$GOPATH/bin"
export PATH="$GOPATH:$GOBIN:$PATH"
alias go="go1.19.2"
OK. Now to get back to what I was doing…
I want to read all the files of a certain type in a directory and all of it’s subdirectories. This is meant to replace the git Commit Tree I am currently traversing.
It seems I was mistakened and both filepath and io/fs have a Walk function:
Oh wait. Nevermind. VS Code doesn’t recognize 1.19…
How to Write Go Code (with GOPATH).
https://go.dev/doc/gopath_code.
Older versions of Go required your code to exist under GOPATH.
It does explains a little about GOPATH and GOBIN.
It references the best reference: go help gopath
.
The Go path is used to resolve import statements. The GOPATH environment variable lists places to look for Go code.
When using modules, GOPATH is no longer used for resolving imports. However, it is still used to store downloaded source code (in GOPATH/pkg/mod) and compiled commands (in GOPATH/bin).
It also references: https://github.com/golang/go/wiki/SettingGOPATH.
Managing Go installations. https://go.dev/doc/manage-install. Explains the “official” way to handle multiple go installations.
GOPATH, GOROOT, GOBIN. https://www.programming-books.io/essential/go/gopath-goroot-gobin-d6da4b8481f94757bae43be1fdfa9e73. Essential Go. Programming Books This is a page from an open source book on Go. It seems like there is one for most popular languages!
Managing Multiple Go Versions with Go. https://lakefs.io/managing-multiple-go-versions-with-go/. LakeFS Blog. Goes into interesting details under the hood.
Multiple versions of go. https://stackoverflow.com/questions/61280008/multiple-versions-of-go. Stack Overflow. This SO question gave me alias idea.
How To List Files In A Directory In Go. https://golang.cafe/blog/how-to-list-files-in-a-directory-in-go.html Golang Cafe. Three different methods to list files in Go. It covers ioutil.ReadDir, filepath.Walk, and, os.File.Readdir, but not io/fs.
Walking with filesystems: Go’s new fs.FS interface.
https://bitfieldconsulting.com/golang/filesystems.
John Arundel.
In-depth explanation about io/fs and the file system abstraction provided by fs.FS
.