Cheatsheet for Golang beginners
1 - Create Git startup repository
See [first demo application in go]
1.1 - Setup Git, SSH and VSCcode locally
- install git and configure global git settings for developer:
pull with rebase ensures that local changes and commits,
can only be added and never change remote commits;
git config --global user.email "[email protected]"
git config --global user.name "RobertTC32"
git config --global init.defaultbranch "main"
git config --global pull.ff "only"
# For windows workstations, add:
git config --global core.autocrlf "true"
git config --global core.editor "notepad"
# For linux workstations, add:
# git config --global core.autocrlf "false"
# git config --global core.editor "nano"
- install ssh and generate ssh public + private key pair for developer:
ssh-keygen -t ed25519 -C "[email protected]"
- install vscode and add "Git Graph" extension
1.2 - Create repository in Github/Gitea
- configure account in github:
choose "Settings" in top-right menu, and change "Profile picture" in "Public profile";
choose "Settings" in top-right menu, click "New SSH key" in "SSH and GPG keys",
and add public SSH key with name "pub-key-XYZ" for user;
in Gitea, language can be changed to English in "User Settings -> Appearance -> Language";
- create repo with "public" visibility,
and "example-", "util-" or "app-" prefix in the name;
this allows minimal organisation because no grouping exist in github;
- while creating the repo,
choose to automatically add a README, gitignore (for Go) and MIT license file;
- change "Settings" in Gitea repo:
keep "main" as name for "Default branch",
disable the following "Features": "Wikis", "Issues" and "Projects";
change the following "Features":
set "Pull request permissions" to "Collaborators only" in "Pull requests";
this simplfies the menu for the repo in github;
- change branching strategy in "Settings" in Gitea repo:
only allow "Allow rebase merging" for "Pull Requests";
no merge commits nor squash merging are allowed,
and head branchis are not deleted after merging pull requests;
this greatly simplifies the commit history while maintaining work organisation;
- after creating git repository in Github,
clone git repo locally,
add readme content, commit the change locally, and push this commit to Github;
1.3 - Branching strategy
This strategy with one shared main branch and multiple feature branches for work in progress:
- prevent loosing work results:
protect shared branches, like main branch
- prevent blocking other developers:
isolate ongoing work per person in feature branches
- catches conflicts early:
often rebase & test localy before merge into main branch
- makes change history easy:
untangle merges in linear history,
by only branching from main branch and merge back after rebase
- improves code quality:
code review & feedback before merge by using pull request (called merge request in Gitlab)
2 - Prepare repo and vscode for go development
??? TODO ???
Setup golang development:
- install go sdk
- go.mod and folder structure
- add "Go" extension in vscode
- implement HelloWorld as console application
Create automation scripts for development:
- install makefile software:
makefile (vs. taskfile, justfile) is used to automate development steps
- add "Makefile Tools" extension in vscode
3 - Develop first web applications
See [todo application which is used as go example]
??? TODO ???
Develop HelloWorld application:
- implement HelloWorld as example web application,
using "Templ" & "net/http" libraries
- install extensions in vscode for web development:
"Live Server", "REST Client",
"Tailwind CSS IntelliSense", "Tailwind Docs", "Tailwind Fold"
Develop simplified Todo application:
- implement Todo as example web application,
using "SqLite" libraries
- add "SQLite" and "SQLite Viewer" extensions in vscode
4 - Containerize and deploy web applications
??? TODO ???
Containerize web applications:
- install docker locally
- add docker extensions in vscode:
"Docker (Extension Pack) -> Container Tools", "Docker DX",
- containerize HelloWorld and Todo application
- build van container image met Alpine of Distroless base image
Deploy web applications:
- add ssh extensions in vscode:
"Remote Development Extension Pack -> WSL & Dev Containers & Remote - SSH & Remote - Tunnels",
"Remote SSH: Editing Configuration Files", "Remote Development", "Remote Explorer"
- deploy HelloWorld and Todo application on server
In the following "Cheatsheet for golang advanced" documentation,
the implementation of the HelloWorld and Todo application will be completed.