Questions tagged [godoc]

GoDoc hosts documentation for Go packages on Bitbucket, GitHub, Google Project Hosting and Launchpad. It can extract and generate documentation for Go programs.

Godoc extracts and generates documentation for Go programs.

Godoc parses Go source code - including comments - and produces documentation as HTML or plain text. The end result is documentation tightly coupled with the code it documents. For example, through godoc's web interface you can navigate from a function's documentation to its implementation with one click.

It has two modes.

Without the -http flag, it runs in command-line mode and prints plain text documentation to standard output and exits. If both a library package and a command with the same name exists, using the prefix cmd/ will force documentation on the command rather than the library package. If the -srcflag is specified, godoc prints the exported interface of a package in Go source form, or the implementation of a specific exported language entity.

References :

http://godoc.org/golang.org/x/tools/cmd/godoc

81 questions
30
votes
5 answers

How do you serve simple documentation for go programs using godoc as a webpage?

I was trying to serve a specific local go file as a documentation web page, but was not able to do it. The official godoc documentation says: With the -http flag (i.e. the godoc command), it runs as a web server and presents the documentation as a…
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
28
votes
4 answers

generate godoc documentation for an entire project?

I've been wrestling with godoc and found that "go doc" is more for providing usage help from the command line for instance: go doc -cmd -u lists the package comment and any functions (or other entities) go doc *function* then shows the…
Bruce Adams
  • 4,953
  • 4
  • 48
  • 111
18
votes
5 answers

godoc command not found

godoc command doesn't work on my system (I'using Linux Mint 20 Ulyana). I've just tried this procedure: install godoc with following command: go get golang.org/x/tools/cmd/godoc Start godoc server: godoc -http=:6060 The result is: bash: godoc:…
Alberto Morreale
  • 435
  • 1
  • 4
  • 11
14
votes
2 answers

What steps are needed to document `package main` in Godoc?

Godoc is a great tool for documenting packages, however it seems to be less useful when it's used against package main. I'll see an output that only displays the notes I've written to myself using //BUG and subdirectories. Godoc only displays…
Mark
  • 872
  • 2
  • 10
  • 19
13
votes
1 answer

What is the equivalent for bigint.pow(a) in Go?

In my use case, I would like to know how the following Java code would be implemented in Go BigInteger base = new BigInteger("16"); int exponent = 1; BigInteger a = base.pow(exponent); //16^1 = 16 I am able to import the math/big package and create…
Dany
  • 2,692
  • 7
  • 44
  • 67
12
votes
1 answer

GoDoc add newline character

I know that Golang supports documentation of functions via single-line comments starting with the name of the function (spelled "func"). However, there's a nauseating side effect: having multiple single line comments will not produce a GoDoc with…
Mike Warren
  • 3,796
  • 5
  • 47
  • 99
8
votes
1 answer

What does it mean if a field is "filtered" in Go?

In the Go documentation a type often shows only the exported fields. For example, the time.Timer documentation (https://golang.org/pkg/time/#Timer) shows the following: type Timer The Timer type represents a single event. When the Timer expires,…
Andy Fusniak
  • 1,548
  • 1
  • 17
  • 28
8
votes
1 answer

Idiomatic way of documenting a Golang program, consisting of one main.go file

I wrote a Go tool which reads files and produces output based on the input. It consists of one main.go file. Where do I document what the tool does, in order to make use of godoc (or just be idiomatic)? // Should I explain it here? package main //…
Kiril
  • 6,009
  • 13
  • 57
  • 77
8
votes
2 answers

Is it bad form to exclude godocs on exported names?

According to "Effective Go" golang.org/doc/effective_go Every exported (capitalized) name in a program should have a doc comment. Let's say I have a view handler on a simple web application // Handle the front page of the website func…
Quentin Donnellan
  • 2,687
  • 1
  • 18
  • 24
7
votes
3 answers

Viewing Example functions with `go doc` command?

If I view a package's documentation via the web at https://pkg.go.dev, the page includes Example test functions. The output of go doc -u -all for a package does not. Is it possible to have such information included?
Colin Fraizer
  • 532
  • 4
  • 14
6
votes
2 answers

List all functions from source code

I have folder with .go files and functions defined inside them. Is it possible to list in command line all function declarations in current folder, probably with godoc? godoc list functions /path/to/fileOrFolder To have such output: func Foo(a, b…
Kenenbek Arzymatov
  • 8,439
  • 19
  • 58
  • 109
6
votes
2 answers

Refer a different package from the godoc of a package

Can someone let me know if it is possible to refer a different package from godoc of a package? For example let's say I have a package src/logger/. In src/logger/doc.go I need to refer src/config/. Something like @see in javadoc. Is there a…
tuk
  • 5,941
  • 14
  • 79
  • 162
6
votes
1 answer

Images in godoc?

Is there any way to add images (local or remote) to the HTML version godoc generates? This is really useful for including diagrams that just can't be explained easily with words.
Elliot Chance
  • 5,526
  • 10
  • 49
  • 80
5
votes
4 answers

How to use a type definition in another file with swaggo?

I am using swaggo generate API document based on godoc syntax. Source folder and files |-post |--controller.go |--response.go For this definition: controller.go package post ... // Index godoc // @Summary Index Post // @Success 200 {array}…
iooi
  • 453
  • 2
  • 10
  • 23
5
votes
2 answers

Godoc documentation not outputting lists

I have, throughout the project I'm responsible for testing and documenting, created documentation for the functions and methods, in the following format: // CheckPermissionArray checks that values is an array that contains the `expectedValue` // //…
Mike Warren
  • 3,796
  • 5
  • 47
  • 99
1
2 3 4 5 6