1

I'm writing Go code for a CNI company that doesn't provide Internet access to the majority of desktops and servers. Due to the nature of the business, documentation is considered very important. I'm looking for a method to scan my code and build static HTML pages that I can host on an internal webserver. Ideally I'd like this to include package main and the functions within it. If static content isn't an option, running a dedicated doc publishing daemon of some kind would be fine. Are there any options?

Steve Crook
  • 1,013
  • 2
  • 13
  • 22
  • https://pkg.go.dev/golang.org/x/tools/cmd/godoc (i'm not sure if `main` is supported though) – mkopriva Mar 02 '21 at 08:06
  • Why do you need static HTML? Why not just run `go doc` normally? – Jonathan Hall Mar 02 '21 at 09:03
  • @Flimzy It doesn't have to be static. In fact, if there's a way to put the code in a repo and have `go doc` generate docs from it, that would be ideal. Currently there seems to be a lot of overlap (and confusion) between `godoc` and `go doc`. How do I document a `package main` using go doc? – Steve Crook Mar 02 '21 at 10:57
  • How to document a package is a separate matter from how to consume that documentation. Which are you asking about? – Jonathan Hall Mar 02 '21 at 10:58
  • @mkrieger1 it might be a solution, I'll give it a try. I'm surprised there isn't a more off-the-shelf solution for documenting Go than having to recompile the godoc package. Is it not a common requirement to document `package main`? – Steve Crook Mar 02 '21 at 11:00
  • @Flimzy I want staff to consume it from a web browser. I don't mind if it's statically generated html or dynamically generated from the source by a tool. My only prereq's are that it can be hosted offline and includes `package main`. – Steve Crook Mar 02 '21 at 11:04
  • Thanks for the clarification. Now it's clear what you need (and that this is a duplicate). See [this answer](https://stackoverflow.com/a/56342340/13860). – Jonathan Hall Mar 02 '21 at 11:11
  • @mkriegar1 Your solution works thanks, although it only documents exported variables/methods. I'll have a dig in the godoc source and see if there's an easy way to override that behaviour. – Steve Crook Mar 02 '21 at 13:11

0 Answers0