michelou / golang-examples

Playing with Go on Windows

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Playing with Go on Windows

Go project 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.

Project dependencies

This project depends on the following external software for the Microsoft Windows platform:

Go packages
We present the installed Go packages in document PACKAGES.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

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

  1. Command go.exe get requires a git.exe executable in %PATH%, and since we've installed Git for Windows we just just need to add bin\ path to our execution path, e.g. c:\opt\Git\bin\
  2. Command go.exe fmt (or utility gofmt) requires a diff.exe executable in %PATH%, and since we've installed Git for Windows we just just need to add usr\bin\ path to your execution path, e.g. c:\opt\Git\usr\bin\
  3. LiteIDE - a simple, open source, cross-platform Go IDE.

[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 and VsDevCmd.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 invoke VsDevCmd.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

mics/May 2024  

About

Playing with Go on Windows


Languages

Language:Go 95.9%Language:Modula-2 4.1%