Skip to content

Instantly share code, notes, and snippets.

@crutchcorn
Last active August 18, 2021 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crutchcorn/c8210af1da794350c24c474643722f49 to your computer and use it in GitHub Desktop.
Save crutchcorn/c8210af1da794350c24c474643722f49 to your computer and use it in GitHub Desktop.
  • Does not support nested functions
    • Must use variable/lambda assignment:
func main() {
	test := func() {
		println("Hello")
	}

	test()
}
  • Uses go keyword for threading stuff:
func main() {
  go func() {
		println("Hello")
	}()
}

Commands

  • go mod init to start project
  • go run file.go to run project

Use go install instead:

Install the latest version of a program,

ignoring go.mod in the current directory (if any).

$ go install golang.org/x/tools/gopls@latest

Install a specific version of a program.

$ go install golang.org/x/tools/gopls@v0.6.4

Install a program at the version selected by the module in the current directory.

$ go install golang.org/x/tools/gopls

Install all programs in a directory.

$ go install ./cmd/...

Switch case based on type https://tour.golang.org/methods/16

Using the 'go doc' command is helpful. You can find out more about a package. Or about a function inside the package. EXAMPLE: go doc time. Now

https://github.com/bobrossrtx/learning-go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment