Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 1.22 KB

CommentsGo.md

File metadata and controls

28 lines (22 loc) · 1.22 KB

Comments

  • In Go, comments play an important role in documenting code.
  • They are used by the godoc command, which extracts these comments to create documentation about Go packages.

Package Comments

  • Package comments should be written directly before a package clause (package x) and begin with Package x ... like this.
// Package kelvin provides tools to convert temperatures to and from Kelvin.
package kelvin

Function comments

  • A function comment should be written directly before the function declaration.
  • It should also explain what arguments the function takes, what it does with them, and what its return values mean, ending in a period):
// CelsiusFreezingTemp returns an integer value equal to the temperature at which water freezes in degrees Celsius.
func CelsiusFreezingTemp() int {
	return 0
}

Golint

  • Golint is a great tool to check for missing comments and other common stylistic issues, which you can read more about at Effective Go.

References