golang 注釋 exported function xxx should have comment or be unexported


0x00 問題

exported function xxx should have comment or be unexported。

0x01 解決

https://golang.org/s/style 在這個頁面中有提到

Comment SentencesSee https://golang.org/doc/effective_go.html#commentary. Comments documenting declarations should be full sentences, even if that seems a little redundant. This approach makes them format well when extracted into godoc documentation. Comments should begin with the name of the thing being described and end in a period:

記錄聲明的注釋應該是完整的句子,即使這看起來有點多余。這種方法使它們在提取到 godoc 文檔時格式良好。注釋應以所述物品的名稱開始,並以句號結束:

// Request represents a request to run a command. type Request struct { ... // Encode writes the JSON encoding of req to w. func Encode(w io.Writer, req *Request) { ... 

正是如此,golint 才會拋出這條警告,聲明你寫的代碼不符合規范。

符合規范的修改:

在方法調用中,能看到注釋信息:

 
分類:  疑難雜症


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM