This repository gathers Go code examples coming from various websites and books. It also includes several build scripts (batch files, Mage files) for experimenting with Go on a Windows machine. |
Ada, Akka, C++, COBOL, Dart, Deno, Docker, Erlang, Flix, GraalVM, Haskell, Kafka, Kotlin, LLVM, Modula-2, Node.js, Rust, Scala 3, Spark, Spring, TruffleSqueak and WiX Toolset are other topics we are continuously monitoring.
This project depends on the following external software for the Microsoft Windows platform:
☛ Go packages
We present the installed Go packages in documentPACKAGES.md
.
Optionally one may also install the following software:
For instance our development environment looks as follows (May 2024) 1:
C:\opt\ConEmu\ ( 26 MB) C:\opt\Git\ (367 MB) C:\opt\go\ (215 MB) C:\opt\VSCode\ (341 MB) %USERPROFILE%\go\ ( 60 MB)
Directory structure ▴
This project is organized as follows:
docs\ examples\{README.md, hello, ...} meeus-examples\{README.md, FirstClassFuncs, ...} PACKAGES.md README.md RESOURCES.md setenv.bat
where
- directory
docs\
contains Go related papers/articles. - directory
examples\
contains Go code examples. - directory
meeus-examples\
contains Go code examples from Meeus's book. - file
PACKAGES.md
presents the Go packages our projects depend on. - file
README.md
is the Markdown document for this page. - file
RESOURCES.md
gathers Go related documents. - file
setenv.bat
is the batch script for setting up our environment.
Batch commands ▴
setenv.bat
3
We execute command setenv.bat
once to setup our development environment; it makes external tools such as code.cmd
, git.exe
and mage.exe
directly available from the command prompt.
> setenv Tool versions: code 1.89.0, go 1.22.3, mage 1.15.0 git 2.45.0, diff 3.10, bash 5.2.26(1)-release > where code git mage C:\opt\VSCode\bin\code C:\opt\VSCode\bin\code.cmd C:\opt\Git\bin\git.exe C:\opt\Git\mingw64\bin\git.exe C:\opt\go\bin\mage.exe
Footnotes ▴
[1] Downloads ↩
- In our case we downloaded the following installation files (see section 1):
-
ConEmuPack.230724.7z ( 5 MB) go1.22.3.windows-amd64.zip ( 70 MB) mage_1.15.0_Windows-64bit.zip ( 1 MB) msys2-x86_64-20240113.exe ( 94 MB) PortableGit-2.44.0-64-bit.7z.exe ( 41 MB) VSCode-win32-x64-1.89.1.zip (131 MB)
[2] External tools ↩
-
- Command
go.exe get
requires agit.exe
executable in%PATH%
, and since we've installed Git for Windows we just just need to addbin\
path to our execution path, e.g.c:\opt\Git\bin\
- Command
go.exe fmt
(or utilitygofmt
) requires adiff.exe
executable in%PATH%
, and since we've installed Git for Windows we just just need to addusr\bin\
path to your execution path, e.g.c:\opt\Git\usr\bin\
- LiteIDE - a simple, open source, cross-platform Go IDE.
- Command
[3] setenv.bat
usage ↩
-
Batch file
setenv.bat
has specific environment variables set that enable us to use command-line developer tools more easily. - It is similar to the setup scripts described on the page "Visual Studio Developer Command Prompt and Developer PowerShell" of the Visual Studio online documentation.
-
For instance we can quickly check that the two scripts
Launch-VsDevShell.ps1
andVsDevCmd.bat
are indeed available in our Visual Studio 2019 installation :> where /r "C:\Program Files (x86)\Microsoft Visual Studio" *vsdev* C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Launch-VsDevShell.ps1 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\vsdevcmd_end.bat C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core\vsdevcmd_start.bat
-
Concretely, in our GitHub projects which depend on Visual Studio (e.g.
michelou/cpp-examples
),setenv.bat
does invokeVsDevCmd.bat
(resp.vcvarall.bat
for older Visual Studio versions) to setup the Visual Studio tools on the command prompt.
[4] Go environment variables ↩
-
> go help environment GOARCH The architecture, or processor, for which to compile code. Examples are amd64, 386, arm, ppc64. GOBIN The directory where 'go install' will install a command. Empty by default. GODEBUG Example: > env GODEBUG=gctrace=1,schedtrace=1000 godoc -http=:8080 (see https://dave.cheney.net/tag/gomaxprocs) GOMAXPROCS Starting from Go 1.5, the default value should be the number of cores. GOOS The operating system for which to compile code. Examples are linux, darwin, windows, netbsd. GOPATH The location of your workspace. NB. To access it from your Go source code simply write import ( "fmt" "go/build" ) fmt.Println(build.Default.GOPATH) GOROOT The root of the go tree.
- For instance:
-
> go env GOARCH GOOS GOROOT GOPATH GOBIN amd64 windows c:\opt\go %USERPROFILE%\go %USERPROFILE%\go\bin
- Run the following command to list the architectures supported on the Windows OS :
-
> go version go version go1.22.3 windows/amd64 > go tool dist list |findstr windows windows/386 windows/amd64 windows/arm windows/arm64