Skip to content

GaryBrownEEngr/go_web_dev

Repository files navigation

Readme

Basic Linux Setup

See the file VM notes.md

Git and GitHub

sudo apt-get install git

Now we need to setup an SSH key with GitHub:

ssh-keygen -t ed25519 -C "your_email@example.com"

More info can be found here.

when prompted to enter where to save the file, just press enter to use the default. Then press enter again to use no passphrase.
Now we need to copy the public key to GitHub. Print out the key using:

cat ~/.ssh/id_ed25519.pub

Then in GitHub, Select: Settings > SSH and GPG keys > New SSH key
more info can be found here. Also enter the key again in GitHub as a signing key.

Now, we should be able to clone the repo using the SSH link.

git clone git@github.com:GaryBrownEEngr/go_web_dev.git

Useful Git Commands

## Fetch all from remote, prune local stuff that has been deleted in the remote.
git fetch --prune --prune-tags

## Show a ansi art graph of the git repo.
git log --all --decorate --oneline --graph

## Checkout an existing branch
git checkout <branch_name>

## Create a new branch
git checkout -b <new_name>

## Delete a local branch
git branch -D <branch_name>

## move to a new location without actually changing any of the local files
git reset --soft <git_hash>

## move to a new location and update all the files locally.
git reset --hard <git_hash>

Private repos and Golang

If you have private repos that golang will need to build from. You will need to configure a replace directive inside of git. Then git will swich to using SSH mode, and use the key, to fetch the repos.

git config --global --add url."git@github.com".insteadOf "https://github.com"

Now we setup automatic signing of commits

git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true

Now, whenever to you create a commit, it will be signed with your key and marked as verified on GitHub.

Set Name and Email

In your GitHub Settings > Email you should check the Keep my email addresses private setting.
Then, with git set your email and username:

git config --global user.email "ID+USERNAME@users.noreply.github.com"
git config --global user.name "NAME"

Then, use the following commands to show all the git configurations you have set.

cat ~/.gitconfig

More info here.

Install VS Code

To install vscode, https://code.visualstudio.com/docs/setup/linux says to use the command: sudo apt install ./<file>.deb Then to run it, just type in "code"

Suggested VS Code Extensions

  • Docker
  • ESLint
  • GitLens
  • Go
  • markdownlint
  • Prettier - Code formatter

I usually turn on auto save in File > Auto Save

Golang

Install Go

The instructions can be found here.

wget https://go.dev/dl/go1.21.6.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.21.6.linux-amd64.tar.gz

Now we need to set the env variables.

code ~/.bashrc

Add the following to the bottom:

# Golang
export PATH=$PATH:/usr/local/go/bin
export PATH=$PATH:$(go env GOPATH)/bin
# as talked about here: https://go.dev/doc/gopath_code#GOPATH
# the /bin needs to added to the path to be able to run "go install"ed things.

# helpful shortcuts:
alias bashrc="code ~/.bashrc"
alias src="source ~/.bashrc"

alias githubactionsgo="echo tidy && go mod tidy && echo build && go build ./... && echo vet && go vet ./... && echo test && go test ./... && echo lint && golangci-lint run"
alias gocoveragehtml="go test -short ./... -coverprofile coverage.out && go tool cover -html=coverage.out -o coverage.html && sleep 2 && firefox coverage.html"

Now either source the update to your terminal, or restart the terminal:

source ~/.bashrc

Now verify your installation.

go version

install golangci-lint

This uses the repo file: .golangci.yaml.
Go here for full instructions. The easiest option is to go install it with the following command:

go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2

Then open your VS code settings and search for go lint and update the option Go: Lint Tool to be set to golangci-lint

install gofumpt

https://github.com/mvdan/gofumpt

go install mvdan.cc/gofumpt@latest

Update the formatting of a file

gofumpt -w <filepath>

Docker

Install Docker

Go here for full instructions.

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

sudo mkdir -m 0755 -p /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

  sudo apt-get update
  sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Make docker work without sudo

Add your user to the docker group using the command:

sudo groupadd docker
sudo usermod -aG docker ${USER}

Then log out and log back in.

Then test if it worked with docker run hello-world

Random Tips

If you want to remove all the dangling docker images: https://nickjanetakis.com/blog/docker-tip-31-how-to-remove-dangling-docker-images

docker rmi -f $(docker images -f "dangling=true" -q)

remove all non-running images:

docker rm $(docker ps -aq)

Test hello world

docker run --name hello-world hello-world
# should download, build, and start an example hello world image.

# now to show it and its status
docker ps -a

# now remove the image
docker rm hello-world

Test locally

docker build -t twertle .
docker run -p 10000:10000 twertle

docker ps # show running containers
docker ps -a # show all containers
docker exec -it loving_hamilton /bin/sh # start a shell session inside the container
docker rm loving_hamilton # delete a docker image.

http://localhost:10000/
http://localhost:10000/guess.html
http://localhost:10000/ticktacktoe
http://localhost:10000/test2.html
http://localhost:10000/api/articles

Keep Windows From Locking

Open Windows PowerShell In the start menu and enter the following script:

$WShell = New-Object -com "WScript.shell"
while($true){
  $WShell.sendkeys("{SCROLLLOCK}")
  start-sleep -milliseconds 100
  $WShell.sendkeys("{SCROLLLOCK}")
  start-sleep -seconds 240
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published