Go supports line comments and block comments. Line comments are the usual style for godoc and package documentation.
Start with // and run to the end of the line.
// Single-line comment
x := 1 // trailing comment
Use /* ... */ for multi-line comments. Prefer line comments in normal code; block comments are fine for disabling a chunk temporarily.
/*
Block comment
*/
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
}
Add, HTTPClient); they appear in documentation and can be used from other packages.add, internalState).gofmt (or let the editor format on save) so comments and code stay consistent.