Hacker News new | ask | show | jobs
by hakube 1767 days ago
How do you add dependencies and in Go? I'm still confused. I use the VSCode extension and the code I wrote that uses external packages gets deleted when I save my file even though the package is installed
2 comments

the vscode extension automatically formats your go file and removes any packages that aren't used in the code.

https://code.visualstudio.com/docs/languages/go#_formatting

Are you using the imports in your file? The VS Code Go addon has "format on save" enabled by default and Go will not compile if there are unused imports - so VS Code deletes the unused imports on save by default.

Otherwise try a "go mod init" in the root of your project.