Running A local GoDoc Web Server (on Ubuntu or similar)

Wouldn’t it be great to carry https://golang.org/ everywhere you go?

The godoc command can be run as a service and provides most of the information available on golang.org including the playground feature but most importantly the package docs.

This is a recipe for running that and making it reachable on http://godoc-local/

I have this set up on all the machines I use and it’s one of the first things I miss if I forget to install it.

Steps

  1. Add name to your /etc/hosts file.
127.0.0.1 godoc-local

2. Install Nginx and make the config. If you don’t like Nginx or have some other local server then you’ll need to adapt this a little. What we’re doing here is listening on port 80 for requests to godoc-local and proxying them to port 19001.

$ sudo apt-get install nginx
$ cat <<EOF > godoc-local-nginx.conf
server {
listen 80 ;
listen [::]:80 ;
server_name godoc-local;
location / {
proxy_pass http://localhost:19001;
}
}
EOF
$ sudo mv godoc-local-nginx.conf /etc/nginx/sites-enabled/
$ sudo service nginx reload

3. Make the systemd config file. You may need to change this depending where you install go or if you want to use a different port.

$ cat <<EOF >godoc-local.service
[Unit]
Description=Go lang docs server
[Service]
ExecStart=/usr/local/go/bin/godoc -http=:19001 -play -index=true
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
$ sudo mv godoc-local.service /lib/systemd/system/
$ sudo systemctl enable godoc-local.service
$ sudo service godoc-local start

You are a winner!

Visit http://godoc-local/ to get you some golang reference.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.