github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/cmd/godoc/doc.go (about) 1 // Copyright 2009 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 /* 6 7 Godoc extracts and generates documentation for Go programs. 8 9 It has two modes. 10 11 Without the -http flag, it runs in command-line mode and prints plain text 12 documentation to standard output and exits. If both a library package and 13 a command with the same name exists, using the prefix cmd/ will force 14 documentation on the command rather than the library package. If the -src 15 flag is specified, godoc prints the exported interface of a package in Go 16 source form, or the implementation of a specific exported language entity: 17 18 godoc fmt # documentation for package fmt 19 godoc fmt Printf # documentation for fmt.Printf 20 godoc cmd/go # force documentation for the go command 21 godoc -src fmt # fmt package interface in Go source form 22 godoc -src fmt Printf # implementation of fmt.Printf 23 24 In command-line mode, the -q flag enables search queries against a godoc running 25 as a webserver. If no explicit server address is specified with the -server flag, 26 godoc first tries localhost:6060 and then http://golang.org. 27 28 godoc -q Reader 29 godoc -q math.Sin 30 godoc -server=:6060 -q sin 31 32 With the -http flag, it runs as a web server and presents the documentation as a 33 web page. 34 35 godoc -http=:6060 36 37 Usage: 38 godoc [flag] package [name ...] 39 40 The flags are: 41 -v 42 verbose mode 43 -q 44 arguments are considered search queries: a legal query is a 45 single identifier (such as ToLower) or a qualified identifier 46 (such as math.Sin). 47 -src 48 print (exported) source in command-line mode 49 -tabwidth=4 50 width of tabs in units of spaces 51 -timestamps=true 52 show timestamps with directory listings 53 -index 54 enable identifier and full text search index 55 (no search box is shown if -index is not set) 56 -index_files="" 57 glob pattern specifying index files; if not empty, 58 the index is read from these files in sorted order 59 -index_throttle=0.75 60 index throttle value; a value of 0 means no time is allocated 61 to the indexer (the indexer will never finish), a value of 1.0 62 means that index creation is running at full throttle (other 63 goroutines may get no time while the index is built) 64 -links=true: 65 link identifiers to their declarations 66 -write_index=false 67 write index to a file; the file name must be specified with 68 -index_files 69 -maxresults=10000 70 maximum number of full text search results shown 71 (no full text index is built if maxresults <= 0) 72 -notes="BUG" 73 regular expression matching note markers to show 74 (e.g., "BUG|TODO", ".*") 75 -html 76 print HTML in command-line mode 77 -goroot=$GOROOT 78 Go root directory 79 -http=addr 80 HTTP service address (e.g., '127.0.0.1:6060' or just ':6060') 81 -server=addr 82 webserver address for command line searches 83 -templates="" 84 directory containing alternate template files; if set, 85 the directory may provide alternative template files 86 for the files in $GOROOT/lib/godoc 87 -url=path 88 print to standard output the data that would be served by 89 an HTTP request for path 90 -zip="" 91 zip file providing the file system to serve; disabled if empty 92 93 By default, godoc looks at the packages it finds via $GOROOT and $GOPATH (if set). 94 This behavior can be altered by providing an alternative $GOROOT with the -goroot 95 flag. 96 97 When godoc runs as a web server and -index is set, a search index is maintained. 98 The index is created at startup. 99 100 The index contains both identifier and full text search information (searchable 101 via regular expressions). The maximum number of full text search results shown 102 can be set with the -maxresults flag; if set to 0, no full text results are 103 shown, and only an identifier index but no full text search index is created. 104 105 The presentation mode of web pages served by godoc can be controlled with the 106 "m" URL parameter; it accepts a comma-separated list of flag names as value: 107 108 all show documentation for all declarations, not just the exported ones 109 methods show all embedded methods, not just those of unexported anonymous fields 110 src show the original source code rather then the extracted documentation 111 text present the page in textual (command-line) form rather than HTML 112 flat present flat (not indented) directory listings using full paths 113 114 For instance, http://golang.org/pkg/math/big/?m=all,text shows the documentation 115 for all (not just the exported) declarations of package big, in textual form (as 116 it would appear when using godoc from the command line: "godoc -src math/big .*"). 117 118 By default, godoc serves files from the file system of the underlying OS. 119 Instead, a .zip file may be provided via the -zip flag, which contains 120 the file system to serve. The file paths stored in the .zip file must use 121 slash ('/') as path separator; and they must be unrooted. $GOROOT (or -goroot) 122 must be set to the .zip file directory path containing the Go root directory. 123 For instance, for a .zip file created by the command: 124 125 zip go.zip $HOME/go 126 127 one may run godoc as follows: 128 129 godoc -http=:6060 -zip=go.zip -goroot=$HOME/go 130 131 See "Godoc: documenting Go code" for how to write good comments for godoc: 132 http://golang.org/doc/articles/godoc_documenting_go_code.html 133 134 */ 135 package main