0

Trying to serve a godoc on a simple, flat code folder. The online docs do not explain how to achieve this SIMPLE task.

So, creating this simple structure,

/tmp/testgodoc$ tree
.
└── src
    ├── main  (just the binary)
    └── main.go

1 directory, 2 files

where main.go is simply

/tmp/testgodoc$ cat src/main.go
// Hello godoc
package main

import "fmt"

// Say Hello
func main() {
    fmt.Println("Hello")
}

When running either in GOPATH or module modes, opening localhost:6060 in a browser does not give the expected result of documenting current folder.

Running in module mode give this output and result:

/tmp/testgodoc$ ~/go/bin/godoc  -goroot=. -http=:6060
using module mode; GOMOD=/dev/null
(when Ctrl-C:) cannot find package "." in:
        /src/main
^C

module mode result

And running in GOPATH mode seems to point to the local standard library:

/tmp/testgodoc$ GO111MODULE=off ~/go/bin/godoc  -goroot=. -http=:6060
using GOPATH mode
^C

GOPATH mode result

ymudyruc
  • 77
  • 9
  • Does this answer your question? [View package documentation locally in a browser](https://stackoverflow.com/questions/56332497/view-package-documentation-locally-in-a-browser) – Arkadiusz Drabczyk Dec 29 '21 at 18:28
  • @ArkadiuszDrabczyk Already read the answer, but none of the options helped. In GOPATH mode "just type `http://localhost:6060/pkg/your/package`" did not work, see 2nd screenshot. And in module mode, already tried the workaroud (`src` folder), but also, didn't work, as you can see in the 1st screenshot. Below answer _did_ work! At least in module mode. – ymudyruc Dec 29 '21 at 19:12

1 Answers1

1

You should put your main package into a subdirectory, maybe like this:

~/go/src/testGoDoc$ tree
├── cmd
│   └── main.go
├── go.mod
└── pkg
    └── test1
        └── test_package.go

and by this you can run both commands:

godoc -http=:6060 #http://localhost:6060/pkg/<module name inside go.mod>/

and

GO111MODULE=off godoc -http=:6060 #http://localhost:6060/pkg/testGoDoc/
S4eed3sm
  • 1,398
  • 5
  • 20
  • Worked in __module__ mode. In GOPATH mode, the package name doesn't appear, and when entering it in the url, doesn't show the expected doc: only `cannot find package "." in: /src/testGoDoc`. – ymudyruc Dec 29 '21 at 19:02