pythoninthegrass / sololearn_golang

Home Page:https://www.sololearn.com/learning/1164

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SoloLearn - Go

Table of Contents

Setup

# install homebrew (macOS)
bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# install asdf
brew install asdf

# install go
asdf plugin-add golang https://github.com/kennyp/asdf-golang
asdf install golang 1.20.4
asdf local golang 1.20.4
asdf reshim

# add asdf to ~/.bashrc
export ASDF_DIR="$HOME/.asdf"
export PATH="$ASDF_DIR/shims:$HOME/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$PATH"
export PATH=$(echo -n $PATH | awk -v RS=: -v ORS=: '!x[$0]++' | sed "s/\(.*\).\{1\}/\1/")

# asdf shell completions
[[ -f "$ASDF_DIR/asdf.sh" ]] && . "$ASDF_DIR/asdf.sh"

# append $GOPATH to existing $PATH (~/.bashrc)
export GOROOT="$(asdf where golang)/go"
export GOPATH=$(go env GOPATH)
export GOBIN=$GOROOT/bin
export PATH=$PATH:$GOBIN

# install delve debugger
go install github.com/go-delve/delve/cmd/dlv@latest
  • VSCode From @ko31: > Open the Extensions Marketplace (Cmd+Shift+X), search Go and install it. > > [O]pen the Command Palette (Cmd+Shift+P) and run the Go: Install/Update Tools command. > > Install all the Go extensions listed there.
  • Known good config
{
    // OTHER CONFIG ITEMS ^^
    // GOLANG-SPECIFIC
    "go.inferGopath": false,
    "go.buildOnSave": "workspace",
    "go.lintOnSave": "package",
    "go.vetOnSave": "package",
    "go.buildTags": "",
    "go.buildFlags": [],
    "go.lintFlags": [],
    "go.vetFlags": [],
    "go.coverOnSave": false,
    "go.useCodeSnippetsOnFunctionSuggest": false,
    "go.formatTool": "gofmt",
    "go.gocodeAutoBuild": false,
    "go.useLanguageServer": true,
    "go.alternateTools": {
        "go-langserver": "gopls"
    },
    "[go]": {
        "editor.codeActionsOnSave": {
            "source.organizeImports": false
        },
        "editor.formatOnSave": true,
    },
}

Usage

# start module and track code's dependencies in tld
go mod init git_username/repo_name

# create directory and move to it
mkdir -p hello && cd $_

# edit hello.go

# run program in working directory (downloads deps automatically from go.mod)
go run .

# install new dependency
go get rsc.io/quote

# cleanup imports
go mod tidy

TODO

  • Extracurricular
    • Calculate datetime from 9/21/2021 (git init) to 7/19/2022 w/Go stdlib
      • I.e., course completion duration
      • 301 days

Further reading

Learn Go | Sololearn

The Missing Package Manager for macOS (or Linux) — Homebrew

Introduction | asdf

asdf to manage multiple Golang on Mac – ookangzheng

Tutorial: Get started with Go - The Go Programming Language

Tutorial: Create a Go module - The Go Programming Language

pkg.go.dev

How to setup Golang with VSCode - DEV Community

Quick Start - GoReleaser

About

https://www.sololearn.com/learning/1164


Languages

Language:Go 100.0%