Home >Backend Development >Golang >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.
(1) Install godoc via your terminal
go install golang.org/x/tools/cmd/godoc@latest
(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": [] } ] }
(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.
The above is the detailed content of Run godoc Automatically. For more information, please follow other related articles on the PHP Chinese website!