- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
展示如何设置 VS Code 以使用 Visual Studio(又名 VScode)调试 Golang App Engine 代码的 Hello World 教程
这是使用 AppEngine 文档中的 Helloworld 代码:
go get -u -d github.com/directmeasure/VScodeDebugGoAppEngine.git
在运行 osX 10.13.3 的 Mac 上。
我已经测试了代码并且服务器在本地工作。我正在尝试弄清楚如何使用调试器输入代码,以便学习如何在其他项目中使用调试器。
这些是我能找到的在 GAE 中使用 VScode 的最佳说明,但它们似乎已经过时,基于对 Golang 的更新(例如切换到 Gcloud、-go_debugging 标志和更改目录结构):
https://medium.com/@dbenque/debugging-golang-appengine-module-with-visual-studio-code-85b3aa59e0f
这是我采取的步骤:
添加到 .bash_profile
export BASEFOLDER="/Users/Bryan/google-cloud-sdk/" .
export GOROOT="/usr/local/go" # this shoudln't have to be set with current Version, doing it to follow the tutorial .
我如何尝试让调试器运行:
dev_appserver.py --go_debugging=true app.yaml
ps aux | grep _go_app
dlv attach <#using the PID from the server binary>
Delve 成功附加到二进制文件。
当我启动调试 session 时,蓝色进度条从未停止水平扫描。
VARIABLE 侧边栏永远不会填充 hello.go 中的变量
断点设置在 hello.go: line 21
Debug REPL 终端显示:
Verbose logs are written to:
/var/folders/mw/0y88j8_54bjc93d_lg3120qw0000gp/T/vscode-go-debug.txt
16:02:31, 2018-4-5
InitializeRequest
InitializeResponse
Using GOPATH: /Users/Bryan/go
fmt.Print(u)
Please start a debug session to evaluate
这是 launch.json 配置:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
//"port": 1234,
"port": 2345 // docs say port should match assigned port headless server, https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code#remote-debugging
// this creates bind error
"host": "127.0.0.1",
"program": "${workspaceFolder}/hello.go",
"env": {},
"args": [],
"showLog": true,
"trace": true,
}
]
}
这是我安装的版本:
go version go1.10 darwin/amd64
$ gcloud version .
Google Cloud SDK 197.0.0
app-engine-go
app-engine-python 1.9.68
bq 2.0.31
core 2018.04.06
gsutil 4.30
VS code extension:
Go 0.6.78
编辑###########################
$ lsof -n -i :8080
Bryan@Bryans-MacBook-Pro Thu Apr 12 17:02:04 ~
$ lsof -n -i :2345
Bryan@Bryans-MacBook-Pro Thu Apr 12 17:03:34 ~
$ ps aux | grep _go_app
Bryan 7433 0.0 0.0 2434840 800 s000 S+ 5:03PM 0:00.00 grep _go_app
Bryan 7426 0.0 0.0 556603172 3896 s002 S+ 5:02PM 0:00.01 /var/folders/mw/0y88j8_54bjc93d_lg3120qw0000gp/T/tmp8GWk1gappengine-go-bin/_go_app
Bryan@Bryans-MacBook-Pro Thu Apr 12 17:03:52 ~
$ dlv attach --headless -l "localhost:2345" 7426 /var/folders/mw/0y88j8_54bjc93d_lg3120qw0000gp/T/tmp8GWk1gappengine-go-bin/_go_app
API server listening at: 127.0.0.1:2345
当我启动调试器时,REPL 显示:
Verbose logs are written to:
/var/folders/mw/0y88j8_54bjc93d_lg3120qw0000gp/T/vscode-go-debug.txt
couldn't start listener: listen tcp 127.0.0.1:2345: bind: address already in use
Process exiting with code: 1
最佳答案
VS Code 永远不会附加到 Delve,因为它正在等待连接到位于 127.0.0.1:2345
的远程 Delve 服务器。如果您在 headless 模式下dlv attach
,在正确的地址上监听,您应该能够连接。
以下步骤描述了如何调试使用 dev_appserver.py
运行的 Go App Engine 应用程序,而无需其他工具/帮助程序。但是,当您对 Go 代码进行更改时,dev_appserver.py
会重新编译并重新启动应用程序,更改 PID Delve 需要调试。 http://github.com/dbenque/delveAppengine可以帮助 Delve 坚持正确的流程。见 here教程。
go get -u -d github.com/directmeasure/VScodeDebugGoAppEngine.git
cd $GOPATH/src/src/github.com/GoogleCloudPlatform/golang-samples/appengine/helloworld
注意:如果你的GOPATH有多个入口,cd
到go get
下载到的目录。
启动 App Engine 开发服务器:
dev_appserver.py --go_debugging=true app.yaml
查找Go进程的PID:
ps 辅助 | grep _go_app
启动 Delve 服务器(选择系统上可用的任何端口):
dlv --headless -l "localhost:2345"attach $GO_APP_PID
创建一个“Go: Connect to server”条目:
注意:这只是一个模板 - 您可以稍后对其进行编辑。
自定义配置以指向您在启动 Delve 时指定的端口。这是我的完整配置:
{ "name": "Launch", "type": "go", "request": "launch", "mode": "debug", "remotePath": "", "port": 2345, "host": "127.0.0.1", "program": "${fileDirname}", "env": {}, "args": [], "showLog": true}
有关在 VS Code(不与 App Engine 一起运行)中调试 Go 代码的一般帮助,请参阅 https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code .
关于google-app-engine - 如何为 Golang 和 AppEngine 设置 VScode 调试 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49329710/
是否为每个 Shiny session 分配了 session ID/ session key (如果部署在 Shiny 服务器上)?如果是,我如何访问该信息?我已阅读文档here然而上网查了一下,并
我正在使用 this koajs session 模块。 我检查了源代码,但我真的无法理解。 我想知道它保存 session 数据的位置,因为我没有看到创建的文件,并且当服务器重新启动时, sessi
实现高可扩展性的一种方法是使用网络负载平衡在多个服务器之间分配处理负载。 这种方法提出的一个挑战是服务器是否具有状态意识 - 将用户状态存储在“ session ”中。 此问题的一个解决方案是“粘性
在负载平衡服务器的上下文中, session 亲和性和粘性 session 之间有什么区别? 最佳答案 我见过这些术语可以互换使用,但有不同的实现方式: 在第一个响应中发送 cookie,然后在后续响
我希望其他人向我解释哪种方法更好:使用 session 或设计无 session 。我们正在开始开发一个新的 Web 应用程序,但尚未决定要遵循什么路径。 无 session 设计在我看来更可取: 优
现在用户在他的权限中有很多角色,我将允许他点击 href 并在新窗口中扮演另一个角色。每个角色都有自己的 session 。 既然浏览器打开窗口不能用新 session 打开,我必须在服务器端想办法。
我正在尝试为express.js Node 应用程序实现 session 存储我的问题是: 如何删除具有浏览器 session 生命周期的 cookie(根据连接文档标记有 expires = fal
在开始在 golang 中使用 session 之前,我需要回答一些问题 session 示例 import "github.com/gorilla/sessions" var store = ses
我读过 Namespaced Attributes . 我尝试使用此功能: #src/Controller/CartController.php public function addProduct(
我正在努力完成以下工作: 根据用户的类型更改用户的 session cookie 到期日期。 我有一个 CakePHP Web 应用程序,其中我使用 CakePHP session 创建了我的身份验证
这是我在这里的第一个问题,我希望我做对了。 我需要处理一个 Java EE 项目,所以在开始之前,我会尝试做一些简单的事情,看看我是否能做到。 我坚持使用有状态 session Bean。 这是问题:
ColdFusion session 与 J2EE session 相比有什么优势吗? ColdFusion session documentation提到了 J2EE session 的优点,但没有
在执行任何任务之前,我需要准确地在创建 session 时创建一个 session 范围变量(因为我的所有任务都需要一个初始 session 范围变量才能运行)。因为,创建 session 时,gra
我们当前的应用使用 HTTP session ,我们希望将其替换为 JWT。 该设置仅允许每个用户进行一次 session 。这意味着: 用户在设备 1 上登录 用户已在设备 1 上登录(已创建新 s
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
假设我在两个或更多设备上打开了两个或更多用户 session (同一用户没有管理员权限)。 在当前 session 中,如果我注销,是否意味着所有其他 session 也会关闭?如果没有,有没有办法通
我正在评估在 tomcat 中使用带有 session 复制的粘性 session 的情况。根据我的初步评估,我认为如果我们启用 session 复制,那么在一个 tomcat 节点中启动的 sess
我开始使用 golang 和 Angular2 构建一个常规的网络应用程序,最重要的是我试图在 auth0.com 的帮助下保护我的登录.我从 here 下载快速入门代码并尝试运行代码,它运行了一段时
我在 Spring Controller 中有一个方法,它接受两个相同类型的参数其中一个来自 session ,另一个来自表单提交(UI)。 问题是在 Controller 方法中我的非 sessio
在我登录之前,我可以点击我的安全约束目录之外的任何内容。如果我尝试转到安全约束目录内的某个位置,它会将我重定向到表单登录页面。如您所料。 登录后,我可以继续我的业务,并访问我的安全约束内外的资源。
我是一名优秀的程序员,十分优秀!