DEV Community 👩‍💻👨‍💻

jguo
jguo

Posted on • Updated on

Learning Golang 101

Go commands.

  • go build compile package and dependencies
  • go clean remove object files and cached files
  • go get add dependencies to current module and install them
  • go install compile and install packages and dependencies
  • go list list packages or modules
  • go run compile and run Go program.
  • go test test packages
  • go version print go version
  • go fmt gofmt (reformat) package sources

For a completed list of commands. Please check here.

Naming Conventions

  • The visibility of a name outside a package is determined by whether its first character is upper case.
  • Prefer simple name instead of a long name.
  • Package name should be good: short, concise, evocative. By convention, packages are given lower case, single-word names; there should be no need for underscores or mixedCaps.
  • The package name is the base name of its source directory; the package in src/encoding/base64 is imported as "encoding/base64" but has name base64,
  • Go doesn't provide automatic support for getters and setters. Use Owner as an example, the getter method should be called Owner (upper case, exported), not GetOwner. A setter function, if needed, will likely be called SetOwner.
  • By convention, one-method interfaces are named by the method name plus an -er suffix or similar modification to construct an agent noun: Reader, Writer, Formatter, CloseNotifier etc.
  • The convention in Go is to use MixedCaps or mixedCaps rather than underscores to write multiword names.

Top comments (1)

Collapse
 
jiayanguo profile image
jguo

regarding go format, I think it would be better to put it in a pre-commit hook. something like
git diff --name-only | xargs go fmt

Let's team up together 🤝

We're hiring for a Senior Full Stack Engineer to join the DEV team. Want the deets? Head here to learn more about who we're looking for.