首页 > 其他分享 >Go入门到入土(一):开发环境安装与调试

Go入门到入土(一):开发环境安装与调试

时间:2023-02-01 14:35:04浏览次数:124  
标签:单击 go 入土 dlv Go delve com 调试

Go入门到入土(一):开发环境安装与调试

1. 安装 Go

按照以下步骤安装 Go:

  1. 在 Web 浏览器中,转到 “go.dev/doc/install”。
  2. 下载操作系统的版本。
  3. 下载后,运行安装程序。
  4. 打开命令提示符,然后运行 go version 以确认已安装 Go。

2. 安装Visual Studio Code

按照以下步骤安装Visual Studio Code:

  1. 在 Web 浏览器中,转到 “code.visualstudio.com”。
  2. 下载操作系统的版本,支持 Windows、Linux 和 macOS。
  3. 下载后,运行安装程序。

3. 安装 Go 扩展

  1. 在“Visual Studio Code”中,单击活动栏中的“扩展”图标,打开“扩展”视图。 或者 (Ctrl+Shift+X) 使用键盘快捷方式。1
  2. 搜索 Go 扩展,然后选择“安装”。2

4. 更新 Go 工具

  1. 在Visual Studio Code中,打开命令面板的“帮助>显示所有命令”。 或者使用键盘快捷方式 (Ctrl+Shift+P)1
  2. Go: Install/Update tools搜索,然后从托盘运行命令。1
  3. 出现提示时,选择所有可用的 Go 工具,然后单击“确定”。1
  4. 等待 Go 工具完成更新。1

过程中可能需要科学。

5. 编写示例 Go 程序

  1. 在Visual Studio Code中,打开将在其中创建 Go 应用程序的根目录的文件夹。 若要打开文件夹,请单击活动栏中的“资源管理器”图标,然后单击“ 打开文件夹”。1
  2. 单击“资源管理器”面板中的“ 新建文件夹 ”,然后为名为“Go”的示例应用程序创建根控制器 sample-app2
  3. 单击资源管理器面板中的“ 新建文件 ”,然后为文件命名 main.go3
  4. 打开终端 “终端 > ”“新建终端”,然后运行 命令 go mod init sample-app 以初始化示例 Go 应用。4
  5. 将以下代码复制到 文件中 main.go 。5
package main

import "fmt"

func main() {
    name := "Go Developers"
    fmt.Println("Azure for", name)
}

6. 运行调试器

  1. 通过在编号行左侧单击左侧,在行 7 上创建断点。 或者将光标放在第 7 行并点击 F9。1
  2. 单击Visual Studio Code一侧的活动栏中的调试图标,打开“调试”视图。 或者 (Ctrl+Shift+D) 使用键盘快捷方式。2
  3. 单击“ 运行并调试”,或按 F5 运行调试器。 然后将鼠标悬停在第 7 行上的变量 name 上以查看其值。 单击调试器栏上的“ 继续 ”或按 F5 退出调试器。3

7. 可能遇见的问题

dlv: failed to install dlv

Installing 1 tool at C:\Users\xxx\go\bin in module mode.
  dlv

Installing github.com/go-delve/delve/cmd/dlv@latest FAILED
{
 "killed": false,
 "code": 1,
 "signal": null,
 "cmd": "C:\\Program Files (x86)\\Go\\bin\\go.exe install -v github.com/go-delve/delve/cmd/dlv@latest",
 "stdout": "",
 "stderr": "C:\\Users\\xxx\\go\\pkg\\mod\\github.com\\go-delve\\[email protected]\\service\\debugger\\debugger.go:32:2: found packages native (proc.go) and your_windows_architecture_is_not_supported_by_delve (support_sentinel_windows.go) in C:\\Users\\xxx\\go\\pkg\\mod\\github.com\\go-delve\\[email protected]\\pkg\\proc\\native\n"
}

1 tools failed to install.

dlv: failed to install dlv(github.com/go-delve/delve/cmd/dlv@latest): Error: Command failed: C:\Program Files (x86)\Go\bin\go.exe install -v github.com/go-delve/delve/cmd/dlv@latest
C:\Users\xxx\go\pkg\mod\github.com\go-delve\[email protected]\service\debugger\debugger.go:32:2: found packages native (proc.go) and your_windows_architecture_is_not_supported_by_delve (support_sentinel_windows.go) in C:\Users\xxx\go\pkg\mod\github.com\go-delve\[email protected]\pkg\proc\native

原因:
your windows architecture is not supported by delve。
delve不支持您的Windows体系结构。

解决方法:卸载并安装正确的go版本。

Couldn't start dlv dap:Error: timed out while waiting for DAP server to start

img

解决方法:在配置文件中加上, "debugAdapter": "legacy",

img

标签:单击,go,入土,dlv,Go,delve,com,调试
From: https://www.cnblogs.com/hanfan/p/17082472.html

相关文章

  • Mongodb常用命令
    最近经常用到mongodb,现把常用命令汇总如下:1、创建集合db.createCollection("modb_test")2、复制集合(同库复制)1db.modb_test.find().forEach(function(x){db.modb_test2.ins......
  • 云小课|手把手教您在PyCharm中连接云端资源进行代码调试
    摘要:让我们看看如何在PyCharm中连接云端资源进行代码调试吧!本文分享自华为云社区《【云小课】EI第54课手把手教您在PyCharm中连接云端资源进行代码调试》,作者:HelloEI。......
  • Django实现向数据库提交数据
    前台界面 post请求需要加上 {%csrf_token%}否则会报错,或者在Settings.py中的 'django.middleware.csrf.CsrfViewMiddleware'注释掉<!DOCTYPEhtml><htmll......
  • (转)Golang sort包排序(详细全集)
    原文:https://blog.csdn.net/qq_43279457/article/details/121730095一、整型首先用下里面提供的最简单的例子,排序一下整形packagemainimport( "fmt" "sort")funcmai......
  • Django实现从数据库查询数据展示在界面
    配置路径,编写前台界面应用之前建好的数据库表参考https://www.cnblogs.com/roselearn/p/17075119.html下图为数据库的数据编写视图from.models......
  • 千姿百态,瞬息万变,Win11系统NeoVim打造全能/全栈编辑器(前端/Css/Js/Vue/Golang/Ruby
    我曾经多次向人推荐Vim,其热情程度有些类似现在卖保险的,有的时候,人们会因为一些弥足珍贵的美好暗暗渴望一个巨大的负面,比如因为想重温手动挡的快乐而渴望买下一辆二十万公里......
  • python mongo查询
    importpymongo#连接数据库环境myclient1=pymongo.MongoClient('mongodb://账号:密码@ip:端口/')mydb1=myclient1["slot"]//dbmycol1=mydb1["ota.versions"]//表x=my......
  • (转)go类型转换strconv详解
    原文:https://blog.csdn.net/xixihahalelehehe/article/details/1046720691.零值变量在定义时没有明确的初始化时会赋值为零值。零值是:数值类型为0,布尔类型为false......
  • Guava:google公司开发的一款Java类库扩展工具包
    Guava是google公司开发的一款Java类库扩展工具包文档https://github.com/google/guavahttps://github.com/google/guava/wikihttps://guava.dev/releases/snapshot-jre......
  • 理解Golang 赋值的并发安全性
     1.什么是并发安全并发安全就是程序在并发情况下执行的结果是正确的。比如对一个变量简单的自增操作count++,在非并发下很好理解,而在并发情况下却容易出现预期之外......