Go Help

Go Doc

Introduction

The Google Go distribution includes a utility named ‘godoc’.  I have not found much documentation.  Here a link: http://golang.org/cmd/godoc/ and another http://golang.org/doc/effective_go.html .  It can be used:

  1. as a reference tool, to show the documentation for the Google Go Project code, or
  2. to create documentation for your own code (under construction)

Google Go Documentation with ‘godoc’

First Option

Open a terminal, or use the terminal plugin in the bottom pane.  Type ‘godoc name of file‘.  For example, to see the documentation for the package ‘fmt’, type ‘godoc fmt’.  The terminal will display the documentation from the source file for the package ‘fmt’.  To see the documentation for ‘godoc’, type ‘godoc godoc’, and so on.

————————

Second Option

  1. If you have not done so already, go back to the Chapter Plugins and install External Tools.
  2. In Gedit go to Tools>Manage External Tools.

You should see a screen similar to below. If you have followed the previous Chapters, this is old hat.

  1. Go to the bottom left of the window and click on the icon just above the help button.  This will create a new tool waiting for input of a name.  Give it a name, I used ‘Go Package Doc’.
  2. Go to the right hand panel and enter the code on the screen shot.  Or copy and paste from here.

——————

#!/bin/bash

xargs godoc

——————–

Below the code panel you can set:

Shortcut Key

Just press the key combination you want to use to for Go Package Doc.  Also, if there is conflict with another tool, click on that tool name, move to the shortcut key field and change it, or press backspace to erase the shortcut.

Save

Set this to nothing.

Input

Set this to current word.

Output

Set this to create new document or display in bottom pane, try them both to see which you prefer.

Applicability

Choose for your situation.

Languages

Above the Close Button, you can make your tool language specific.  If you installed the syntax highlighter previously, Go will come up as one of your language choices.  This creates a new language category or adds your tool to an existing one in the left pane. You can check multiple languages.  I checked the box for Plain Text, and the one for Go.  If you set it to all languages, then it will always come up on the Tools>External Tools drop down box.

Close Window

TEST

Open Gedit. In a new document type ‘fmt’ ( no quotes).  Put the cursor on ‘fmt’ and Press your Go Package Doc shortcut key, or go to the menu and go to Tools>External Tools>Go Package Doc.  You should see a new document tab or a display in the bottom pane, depending on your settings, with the documentation for the ‘fmt’ package. This works because we have the Language set to Plain Text.  You can copy and paste.

Because we also set the Language to Go, we can look at Go source code and when we want to see package documentation for an import, just put the cursor on the package name and run Go Package Doc.

———————–

NEXT STEP

After you have created the above Go Package Doc Tool,  I have provided a file  gopkg with the name and description of the current packages.  Download it and rename it gopkg or gopkg.txt and save.

  1. Open Gedit,
  2. Open this document,
  3. Put the cursor on the name of a package and
  4. Run Go Package Doc.

I created a Gnome Panel Launcher for Gedit that starts Gedit with this file.

Create a free website or blog at WordPress.com.

%d bloggers like this: