Using Go
TL;DR (Too long; Didn’t read)
This post explains how to install go and setup a project with a package and one module. The reasoning for GO and Raylib: Its what I want to do, and I think you will like it too.
Intro
GO is low-level yet simple. It is as powerful as C and is more secure and modern. When I say simple, I mean you should have a firm understanding of the basics in a week.
You heard it was for server backends for websites? Its a general purpose language meaning it was designed for almost all scenerios including writing operating systems.
Why isn’t it more popular? Well popular is what everyone else like or is doing. Fuctional programming (i.e. Rust) is not for everyone and Object Oriented programming is on its way out. Go has a new modern approach without all the baggage that a language designed for a specific use has.
I will use Raylib for the UI (especially for games) though there are many choices. see Awesome-GO. Do you like GoDot?
My choice comes down to one criteria - decent performance on low powered devices, without compromising those with very high performance. GOAL - I want to help users here with low powered devices too.
Where do we start?
Choose an engine/library
Take a look at Awesome Go game development link i.e. https://awesome-go.com/game-development/
What we will need
- Go
- Git
- IDE opr text editor - Go supports a few IDE’s directly. VSCode or a jetbrains ide is a good choice.
Get Go
Go to GO.DEV downloads follow the instructions for your system.
Windows users choose either one - the msi is simplest
- get the windows MSI that suits your system. For Mine it is go1.23.4.windows-amd64.msi.
- Use WinGet (you may have to download that from the microsoft store)
I downloaded the MSI and ran it. You are asked to accept the terms and shown where the go files are installed.
The standard install creates two entries into your environment variables (PATH) - one to the bin folder in your path and the other is GOPATH which points to your home folder i.e. [home]/go folder.
Get Git
Generally a version control system is recommended and GIT is the current favorite. You may need a GITHUB or BITBUCKET account. Don’t worry they have free tier which is very generous. It is on the cloud but you can keep it local too.
Get it from Git-scm.com downloads
Once again a typical install. You may need to remove the file name limit that Windows imposes by checking off a tick box on one of the screens.
we use this at the end of this post
Get VS Code (If you want)
VSCode can be found on the microsoft visual studio website.
Go.dev has a using an IDE page and will tell you how to set up the common IDE’s. However if you open up code and search for the “go” extension you should have no trouble.
Go modules
for now just think of modules as Namespaces or
Create Your first Module
Installing go will likely create a “go” folder in your HOME (PROFILE) directory. If installing GO did not create a “go” folder in your HOME directory you may do this from the terminal or your file explorer.
from terminal - starting in your profile directory (HOME):
mkdir go
Now that you have a Go folder/directory
cd go mkdir src cd src
We will work from here as it is the default and requires less setup
Our workspace is src (this a go default). We will now continue and make our first module. We create a folder
mkdir hello cd hello
Then do the following from the terminal
go mod init example.com/hello
We create the following
hello.go
package main
import "fmt"
func main() {
fmt.Println("Hello, world")
}
We can run this short app using this terminal command
go run hello.go
great it should display “Hello, world” below our command we typed if all is well
you can now run the following to make a module and Build our code
go mod tidy
go build .
Initialize our git repository and make an initial commit
git init
git add .
git commit -m "initial commit"
read up on git you only need a few commands or a git GUI to suceed.
Learn Go
You can learn here, but don’t stop here.
The Go web site has some Go tutorials and a list of places to learn so does Awesome Go and many others.
Books and Tutorials
- A list of GO e-books
- A list of GO tutorials
- The Go Language Website - Learn
- Exercism.org - recommended teaches a few basics and then challenges you with interactive tests on the site so that you can practice what you learn.
- Avery makes games this is one short series
I suggest reading learn go with tests. It does leave you with some questions especially when trying to get the second test file working, though it gives a very good idea how to make and use tests.
Modules are important in GO. If you compile/build the project it will protest with an error if go.mod does not exist - we will get to this later.
Take a look for “Go & Games” from the series page.