play-with-go.dev
is a series of interactive browser-based guides that lead you on a tour
of the Go command and Go modules.
If you have not done so already, head over and complete the Go Tour; it presents an excellent interactive introduction to Go the programming language.
play-with-go.dev
helps you take the next steps to practically getting things done with Go, covering various topics
from writing tests, understanding Go modules, static analysis, code generation and much more.
Structure of play-with-go.dev
guides
play-with-go.dev
guides are best viewed on a laptop or desktop device with a good sized screen. The left hand side
(the bit you are reading now) is the guide itself, otherwise known as the prose. The right hand size is an interactive
terminal that is connected to a remote virtual session, hosted on Google Cloud. Do not
enter any personal credentials/details into the interactive terminal. We make no guarantees on the security of these
remotes sessions.
For Go-related guides, the remote session runs with a user and working directory as follows:
$ whoami
gopher
$ pwd
/home/gopher
Throughout each guide (prose) you will see clickable command and code blocks. For example, click on the following command block:
$ echo '*** !!! CLICK ME !!! ***'
*** !!! CLICK ME !!! ***
Clicking on command block causes those commands to run in the interactive terminal on the right hand side. Command
blocks are indicated by a $
sign at the beginning of a line; the output from that command (if there is any) will be on
the lines that follow. Command blocks can contain multiple commands:
$ mkdir hello
$ cd hello
You can also upload code/content to our interactive session using code blocks. Click on the following code block to
upload contents to README.md
:
This is README.md.
Hello, gopher!
If a later code block updates a file, we typically highlight the bits that have changed:
This is README.md.
Hello, gopher!
We made a change!
Now that we have uploaded README.md
we can run another command to show us its contents:
$ cat README.md
This is README.md.
Hello, gopher!
We made a change!
Remote source code repositories
Some guides need you to publish code to a remote source code repository. For such guides, a unique user is automatically
created for you in the gopher.live
gitea
instance. Repostitories are
created beneath that user account. For example, for this guide we have created the unique user {{{.GITEA_USERNAME}}}
and a repository called hello
.
Let’s add the README.md
file we created earlier to this remote repository.
Initialise a local git
repository and add the remote:
$ git init -q
$ git remote add origin https://{{{.REPO1}}}.git
Add and commit the README.md
file we created earlier:
$ git add README.md
$ git commit -q -m 'Initial commit'
Push the commit to the remote repository:
$ git push -q origin main
remote: . Processing 1 references
remote: Processed 1 references in total
It’s as easy as that. Authentication is taken care of for you. The user and repository will be destroyed after 3 hours along with the guide session.
I’m lost, help!
Don’t worry, there are people who can help! Either head over to #play-with-go
on Gophers
Slack (sign-up) or raise an
issue in our GitHub issue tracker.
Next steps
As a next step you might like to consider: