是否可以在VSCode中更改golang项目的工作目录?



我有一个这样的项目结构:

app
-configs
-config.yaml
-server
-cmd
-app
-main.go
-internal
-config
-config.go

Insideconfig.goI want read the config fromconfigs/config.yaml.

但是据我所知,由于我的工作目录等于主文件的路径,当我传递这样的路径"configs/config.yaml"时,我得到一个错误file not found

我看到在intellij idea(如果我没弄错的话)在类似的情况下,他们只是改变了工作目录some_path/app,一切都很好。在VSCode也是可能的吗?也就是说,要更改工作目录还是有其他方法来实现这一点?

intellij idea的工作目录为";cwd"参数,在vscode中启动。Json格式如下:

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd/server",
"cwd": "${workspaceFolder}" // like intellij idea of working directory 
}
]
}

相关内容

最新更新