DEV Community

Tony Metzidis
Tony Metzidis

Posted on

1

Run godoc Automatically

VSCode has a fantastic task runner, with lots of configuration options for when and how the task should be run.

Let's set up godoc to run whenever you open the project. It will display a push notification linking you to godoc server within your browser.

STEPS to Add

(1) Install godoc via your terminal

 go install golang.org/x/tools/cmd/godoc@latest
Enter fullscreen mode Exit fullscreen mode

(2) Add the task with CTRL-SHIFT-P, "Configure Tasks" . This edits ./vscode/tasks.json
(3) Add the following task to the tasks array (copy the individual task object below)

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "godoc",
            "type": "shell",
            "command": "godoc",
            "options": {
                "cwd": "${workspaceFolder}",
                "shell": {
                    "args": ["-c"],
                    "executable": "/bin/sh"
                }
            },
            "runOptions": {"runOn": "folderOpen"},
            "presentation": {
                "echo": true,
                "reveal": "never",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "problemMatcher": []
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

(4) Run the task. You can run the task with CTRL-SHIFT-P → "Run Task" → "godoc" or by reopening your window. A notice will show linking you to godoc. Or you can find the link using the "Ports" tab and clicking the godoc URL.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more