'Cobra init' run-over of my main.go


I’ve had the most horrible experience…
While trying to perform ‘cobra init’ from my VSCode for the first time, the execution ran over my previous main.go contents, and I can’t figure out if this is recoverable…

Do you have any suggestions or insights for the current situation?


I’m not familiar with Cobra, but maybe there’s a hidden .main.go or main.go.bak with your original file? Are you using source control like Git or Subversion so that you can rollback? Are your files in some synchronized folder like with Dropbox, Google Drive, OneDrive, etc.? If not, I’m afraid that it’s just like any other time a file is overwritten: You’ll have to redo it from scratch if you don’t have a backup.

This is why version control systems exist …

That and your main.go should not have much more than a call to another function in another file that has the code. Kinda like the main.go that you get when you do cobra init

thanks for the awesome information.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.