Code-Memo

Comments

Go supports line comments and block comments. Line comments are the usual style for godoc and package documentation.

Line comments

Start with // and run to the end of the line.

// Single-line comment
x := 1 // trailing comment
Block comments

Use /* ... */ for multi-line comments. Prefer line comments in normal code; block comments are fine for disabling a chunk temporarily.

/*
   Block comment
*/
Documentation comments

Comments that appear immediately before a declared identifier (package, type, func, const, var) are treated as documentation by go doc and pkgsite. For packages, put a package comment in one file (often doc.go) starting with // Package packagename ....

// Add returns the sum of a and b.
func Add(a, b int) int {
	return a + b
}
Naming and style