DEV Community

jguo
jguo

Posted on • Edited on

1 1

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.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more