How to run pkg.go.dev locally as a godoc replacement? - go

godoc has been removed from the go standard install since 1.12 and looks like it wont be updated anytime soon. pkg.go.dev at least appears to be its successor. It also has additional documentation features like grabbing the README.md file and rendering it in the documentation page.
For these reasons I was hoping to switch over to using pkg.go.dev locally to view and create documentation for small internal packages. The major issue is that unlike godoc there does not seem to be a clear usage guide. I also do not know if pkpg.go.dev is completely overkill for this task. So I would like to know:
Can and should pkg.go.dev be used as a local godoc replacement?
If yes, how would I run it for this task?

Run pkgsite locally.
go install golang.org/x/pkgsite/cmd/pkgsite#latest && pkgsite
References:
https://tip.golang.org/doc/comment
https://pkg.go.dev/golang.org/x/pkgsite/cmd/pkgsite

You can use the x/tools/godoc that has the previous godoc tool

Running godoc [1] on its own worked for me, but was really slow because it generates docs for every single package in the standard library, while I only care about the local package that I am working on. To that end, if your package is in a folder called something, you can move the folder so that it looks like this:
godoc/src/something
Then, go to the godoc folder, and run
godoc -goroot .
Then, browse to localhost:6060. Alternatively, another site is available for
Go docs [2].
https://github.com/golang/tools/tree/master/cmd/godoc
https://godocs.io

Related

vscode: How to search in installed package?

I want to search in the go pkg go-git.
ctrl+shift+f searches only in my module.
Probably this will not directly answer, but it's an workaround, that I personally prefer:
Hovering over a function, that is from a foreign package, VS Code shows the godoc description. There is always a link to pkg.go.dev (This link is for the PlainClone example):
Following it you are redirected directly to GO's package website.
Here is already a nice list with the module's functions.
if you want to dive deeper:
On the top of the repository there is the link to the repo host.
Experiences show, that this is mostly Github. While GitHub's search used to be proscribed, it can nowadays be a mightful tool:
https://docs.github.com/en/search-github/searching-on-github/searching-code#search-within-a-users-or-organizations-repositories
Again I mention that is very subjective, but GO's complex way of storing modules locally with it's many env variables and stuff made me feel using the internet is more comfortable =)

How to install static content removed from golang with go 1.13

Before go 1.13, I could run the version of godoc that came with go as godoc -http localhost:6060. This would not only show me the documentation for all of my source code, but also static content from the go web page, including for example the go language specification.
What's the easiest way to make this content available offline with go 1.13? I was of course able to install godoc and view my own godoc documentation, but not the other web site contents. I tried things like go get -u golang.org/x/website to no avail.
For what it's worth, I'm using arch linux, so if there's no way to do this with go get I'd also be interested in installing an arch or AUR package.
The static content hasn't stopped being shipped with go (it's a bunch of .html files in $GOROOT/doc/), only the godoc server has. If you install godoc, addresses like http://localhost:6060/ref/spec work just fine; I just tested it. If it's not working for you, perhaps the -goroot flag to godoc would be of use?

How do I use github packages in go?

Sorry, very much a newbie golang question. I have a github project named journalbeat that I am modifying.
When I clone that repository I can set the GOPATH and run go get to grab all the imports and it places them into src.
I have a new import I want to add.
import "github.com/danwakefield/fnmatch"
but it doesn't grab it. How does simply running go get determine whether something is downloaded or not?
And finally, the vendoring system is used. How do I populate that with the fnmatch? do I create it manually? it all seems very cumbersome.
I thought go get was meant to make all this easy?
Try instead a dependency manager: the most recent and actively developed one is golang/dep.
Reading dep "issue" 943, use:
dep ensure
That will set up vendored dependencies through import analysis, and you can configure locking those down if need be.
Try go get with the verbose flag -v like:
go get -v github.com/danwakefield/fnmatch
This will show you more details. Post the result here.
we use Glide package management tool for GO. Go check it out gitHub link

godoc without showing source code

I got several Go projects which is documented compatibly with godoc. We use godoc to share doc and code internally as a doc server without significant problem. However we need more control on opening code when we want to share doc with 3rd party. Is there a way to run godoc in a special mode that showing types and docs but never link to or showing source code?
I've tried
godoc -http=0.0.0.0:8090 -links=false -src=false
but not working, still can link to type definition code. Just wondering if missed sth. Go version, 1.3.
The src file only refers to command line mode, not to server mode, so it won't help you. The way I see it there are a few options:
Rewrite godoc for your needs and use your own fork.
Don't use the server mode, render the docs in command line mode and just create a server out of that.
Better yet (I'm not entirely sure 2 will work) - rewrite the templates a bit so the source code won't be linked. But you'll still need to make sure people who enter the path manually won't see the code so it will require fudging the source templates as well. or...
Maybe the simplest thing - run it behind nginx or a similar reverse proxy, and make sure the /src path in the server is closed to outside visitors, or password protected or whatever. That way your internal team can still use it.
Personally I'd go with 4, it's a couple minutes of work and will be the most robust and flexible solution.

Golang requirements.txt equivalent

Coming from a python/django world, it'd be great to have something like a requirements.txt equivalent for go/revel. How can I do this? I know I can just write a requirements.txt file and then do something like
cat requirements | xargs go get
But what if my requirements ALSO have requirements? The above command would attempt to "go get" them, and then they'd fail to build, since I don't have those requirements installed.
Is there something I'm missing?
The command go get does exactly what you need: It finds all dependencies and downloads and installs the missing ones. Focus on "all": go get really traverses your dependency graph.
Have a look at the documentation:
https://golang.org/cmd/go/#hdr-Add_dependencies_to_current_module_and_install_them
The Go documentation is really clean, short and well written. I would recommend always to have a look at the documentation first before making assumptions which are based on experience with other tools or tool-chains.
They also provide useful blog posts, https://blog.golang.org/using-go-modules
I just found that the kubernetes guys actually have created an overview page for themselves here.
Summary is this: Currently stable is Glide and the cool new toy is called dep

Resources