第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 vscode 中未檢測(cè)到 env 文件

在 vscode 中未檢測(cè)到 env 文件

Go
胡說(shuō)叔叔 2023-01-03 16:13:44
我有一個(gè)my-project多根工作區(qū):- my-project   - my-project-api-gateway   - another-root-folder-we-dont-care-about這是我的launch.json配置文件my-project-api-gateway{  // See https://code.visualstudio.com/docs/editor/debugging#_launchjson-attributes  // and variables here https://code.visualstudio.com/docs/editor/variables-reference  "version": "0.2.0",  "configurations": [    {      "name": "my-project-api-gateway",      "type": "go",      "request": "launch",      "mode": "debug",      "envFile": "${workspaceFolder}/.env", ----> Error loading .env file      "program": "${workspaceFolder}/src/main.go"    }  ]}調(diào)試控制臺(tái)輸出Starting: /Users/me/go/bin/dlv dap --check-go-version=false --listen=127.0.0.1:53890 --log-dest=3 from /Users/me/path/to/project/srcDAP server listening at: 127.0.0.1:53890Type 'dlv help' for list of commands.2022/07/20 10:30:52 Error loading .env fileProcess 13526 has exited with status 1Detachingdlv dap (13508) exited with code: 0謝謝你的幫助dlv、go、gopls 和 vscode 版本? dlv versionDelve DebuggerVersion: 1.8.2? go versiongo version go1.18 darwin/amd64? gopls -v versionBuild info----------golang.org/x/tools/gopls v0.9.1? code -v1.69.2擴(kuò)展Go for Visual Studio Code是 v0.35.1
查看完整描述

1 回答

?
慕村225694

TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊

這里的技巧是我.env在我的工作區(qū)文件夾下: ${workspaceFolder}/.env,但vscode沒(méi)有${workspaceFolder}用作我通過(guò)調(diào)用我的 go 函數(shù)來(lái)獲取文件的當(dāng)前工作目錄。.envos.Getwd()


load_eng.go摘錄如下:


curDir, err := os.Getwd()

if err != nil {

    log.Println(err)

}

loadErr := godotenv.Load(curDir + "/.env")

if loadErr != nil {

  log.Fatalln("can't load env file from current directory: " + curDir)

}

所以,我只需要通過(guò)在我的文件中$cwd添加來(lái)設(shè)置當(dāng)前工作目錄:"cwd": "${workspaceFolder}"launch.json


"configurations": [

    {

      "name": "My Application",

      "type": "go",

      "request": "launch",

      "mode": "debug",

      "envFile": "${workspaceFolder}/.env",

      "program": "${workspaceFolder}/src/main.go",

      "cwd": "${workspaceFolder}"

    }

  ]

有用的資源:


https://code.visualstudio.com/docs/editor/variables-reference#_predefined-variables


https://github.com/golang/vscode-go/wiki/debugging


查看完整回答
反對(duì) 回復(fù) 2023-01-03
  • 1 回答
  • 0 關(guān)注
  • 373 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)