安裝godoc
go get -v golang.org/x/tools/cmd/godoc
godoc幫助信息
godoc --help wangruixing@MacBook-Pro
usage: godoc -http=localhost:6060
-analysis string # 只支持GOPATH模式,不考慮使用
comma-separated list of analyses to perform when in GOPATH mode (supported: type, pointer). See https://golang.org/lib/godoc/analysis/help.html
-goroot string # 指定GOROOT路徑
Go root directory (default "/usr/local/go")
-http string # 指定web啟動IP和端口號
HTTP service address (default "localhost:6060")
-index
enable search index
-index_files string
glob pattern specifying index files; if not empty, the index is read from these files in sorted order
-index_interval duration
interval of indexing; 0 for default (5m), negative to only index once at startup
-index_throttle float
index throttle value; 0.0 = no time allocated, 1.0 = full throttle (default 0.75)
-links
link identifiers to their declarations (default true)
-maxresults int
maximum number of full text search results shown (default 10000)
-notes string
regular expression matching note markers to show (default "BUG")
-play
enable playground
-templates string
load templates/JS/CSS from disk in this directory
-timestamps
show timestamps with directory listings
-url string
print HTML for named URL
-v verbose mode
-write_index
write index to a file; the file name must be specified with -index_files
-zip string
zip file providing the file system to serve; disabled if empty
要使用-index標記開啟搜索索引,這個索引會在服務器啟動時創建並維護。否則無論在Web頁面還是命令行終端中提交查詢都會返回錯誤“Search index disabled: no results available”。
索引中提供了標示符和全文本搜索信息(通過正則表達式為可搜索性提供支持)。全文本搜索結果顯示條目的最大數量可以通過標記-maxresults提供。標記-maxresults默認值是10000。如果不想提供如此多的結果條目,可以設置小一些的值。甚至,如果不想提供全文本搜索結果,可以將標記-maxresults的值設置為0,這樣服務器就只會創建標識符索引,而根本不會創建全文本搜索索引了。標識符索引即為對程序實體(變量、常量、函數、結構體和接口)名稱的索引。
正因為在使用了-index標記的情況下文檔服務器會在啟動時創建索引,所以在文檔服務器啟動之后還不能立即提供搜索服務,需要稍等片刻。在索引為被創建完畢之前,我們的搜索操作都會得到提示信息“Indexing in progress: result may be inaccurate”。
links
false:
true:
godoc -http=localhost:9000 -goroot=/Users/wangruixing/go -index -v