How to install static content removed from golang with go 1.13 - go

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?

Related

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

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

Check if a new version of go based binary is available using go get

I am a little bit new to Go, specifically go get mechanism to download single binaries (CLI apps). Some cool projects in github allow you to download cli apps using go get. How can I check that binary that I installed is outdated? I am looking for something like debian based apt update that checks for newest package versions without installing them.
As an example. Let's say that I installed lazygit using go get github.com/jesseduffield/lazygit. And after a while a new version was released in github . Is it possible to check new version of binary using go get?
I checked the help and found the -u flag. Use go get -u github.com/jesseduffield/lazygit to update the tool.
None of this is speicific to the GitHub.

Shortcut to install libraries in Goland

I'm following the instructions in https://golang.org/doc/code.html#Library and trying to use Goland. I'm surprised though that I can't find a fast way to install the library I'm writing. According to the tutorial, you should use install to install your code in the pkg or bin folders, yet I can't find a way to do this in Goland other than writing it in the console.
What am I missing?
There are two ways to import Go packages using GoLand:
copy-paste the code that needs the package into the IDE and then on the import declaration use Show Intention to see the list of actions available and choose the first one, go get -t <package-name>/...
copy the URL of the Github repository into your clipboard, switch to the IDE and use the pop-up to run go get on the package. The pop-up disappears after a few seconds.
I've attached the image which shows these options.
This will download libraries in the correct GOPATH directory and run go install as part of the go get action.
As for installing the libraries that you are developing in GOPATH/pkg, there is no need for that, as soon as you run any configuration from the IDE, be it an application or a test that depend on those libraries, the IDE will install those libraries as well.

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.

Install exp/html in Go

It looks like Go doesn't support HTML web parsing tools/packages yet, despite it already providing XML scraping via encoding/xml. So how can I install exp/html package in Go?
As far as I know, all the answers, at least I stumbled upon on the Web with 10 minutes worth of searching, didn't return the correct answer; when I tried to run those, I got the error cannot find package XXX in YYY or no Go source files in XXX.
So as of now, can I install it without re-compling and setting the whole Go environment from scratch? Or am I missing something?
I'm on OS X 10.8 and run Go version 1.1, which I installed from OS X package installer.
For your information, these code didn't make it.
go get code.google.com/p/go/src/pkg/exp/html
go get code.google.com/p/go.exp/inotify
Thanks.
I just tried:
go get code.google.com/p/go.net/html
and it seemed to work.
I have a feeling it's been moved from the exp library to the new net library.
EDIT: Documentation & browseable repo.
With go 1.4 (November 9th, 2014), you will have to type:
go get golang.org/x/net/html
See:
"New Import paths for Go sub-repositories".
"Go 1.4 subrepo renaming".

Resources