Go Wiki: コメント

すべてのパッケージには、パッケージコメントが必要です。これは、パッケージ内のファイルの1つで`package`ステートメントの直前に記述する必要があります。(1つのファイルにのみ記述する必要があります。)「Package *packagename*」で始まる1文で始まり、パッケージの機能の概要を簡潔に説明する必要があります。この導入文は、godocのパッケージ一覧で使用されます。

続く文や段落で、より詳細な情報を提供できます。文は適切に句読点を付ける必要があります。

// Package superman implements methods for saving the world.
//
// Experience has shown that a small number of procedures can prove
// helpful when attempting to save the world.
package superman

ほぼすべてのトップレベルの型、定数、変数、関数はコメントが必要です。barのコメントは「*bar* floats on high o’er vales and hills.」という形式にする必要があります。コード中で大文字で表記されていない限り、*bar*の先頭文字は大文字にしないでください。

// enterOrbit causes Superman to fly into low Earth orbit, a position
// that presents several possibilities for planet salvation.
func enterOrbit() os.Error {
  ...
}

コメント内でインデントしたテキストはすべて、godocによってプリフォーマットされたブロックとしてレンダリングされます。これにより、コードサンプルが容易になります。

// fight can be used on any enemy and returns whether Superman won.
//
// Examples:
//
//  fight("a random potato")
//  fight(LexLuthor{})
//
func fight(enemy interface{}) bool {
  ...
}

このコンテンツはGo Wikiの一部です。