如何創建可見的 Go 檔案?
這很容易為 go 中的任何函式創建檔案,如下所示:
package main
// documentation example
func DocumentedFunction() bool {
return true
}
當我呼叫該函式時,我可以看到該檔案:

我可以撰寫可以從編輯器/IDE 中看到的包檔案嗎?我是否必須安裝其他工具才能實作包檔案的類似行為?
uj5u.com熱心網友回復:
根據Go 官方檔案和此鏈接,應該可以像為函式創建檔案一樣為整個包創建檔案:
要記錄一個函式、型別、常量、變數,甚至是一個完整的包,請在其宣告之前直接寫一個常規注釋,中間沒有空行。
例如:strings包:
// Package strings implements simple functions to manipulate UTF-8 encoded strings.
//
// For information about UTF-8 strings in Go, see https://blog.golang.org/strings.
package strings
..
..
rest of the file
所以你基本上只是在package關鍵字上方添加一個普通的注釋。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/385989.html
上一篇:洗掉XML中“:”之前的所有字符
