gpt4 book ai didi

json - 插入调试 env json 属性 VSCode

转载 作者:IT王子 更新时间:2023-10-29 02:11:04 24 4
gpt4 key购买 nike

我想像下面这样配置 go debug env json 属性

DEV_PROP=
'{
"run": "app.sh",
"server_port": "8081",
"app_url":"http://localhost:3000"
}'

我试图在环境中输入以下内容,但出现错误

"configurations": [

{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {

},

当我将 DEV_PROP 插入 env 对象时,我遇到了很多错误,我尝试使用配额但没有成功,知道吗?

最佳答案

你试过这种方法吗?

{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {
"run": "app.sh",
"server_port": "8081",
"app_url":"http://localhost:3000"
},

如图所示http://techbrij.com/visual-studio-code-tasks-debugging

同样按照惯例,环境变量应该全部为 UPPER_CASE,如此处所示 https://stackoverflow.com/a/673940/6314736

所以它应该是这样的:

{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {
"RUN": "app.sh",
"SERVER_PORT": "8081",
"APP_URL":"http://localhost:3000"
}
}

此外,如果您想为开发环境单独启动,只需复制此对象并将“名称”属性更改为您喜欢的任何内容。它应该在配置数组中。

编辑作为Adrian指出,我对这个问题的回答是错误的。正确答案是用反斜杠转义双引号。“环境”:{
"DEV_PROP":"\"run\":\"app.sh\",\"server_port\":\"8081\",\"app_url\":\"http
://localhost:3000\"}"
}

我已经测试过了,它工作正常。 Picture for proof

关于json - 插入调试 env json 属性 VSCode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47145313/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com