How do I fix Golang package issues?

1.7k views Asked by At

I'm starting a Golang course and I'm super new to developing, but having issues with packages. Currently on a lecture about Variables when I go to run the code it gives me

package variables is not in std C:\Program Files\Go\src\variables

I think it might be an environment variables' issue as these keep coming up but I'm very unsure, I've tried looking at the paths in my environment variables and I don't seem to be finding the issue. Could anyone take a look at my screenshots and assist me with the issue? Thank you

environment variables
code im running in VS Code

I've ensured that the mod file is within the lectures project, I've checked my system environment variables. When running code in git I've made sure I'm in the working directory as to where the variable lecture is

2

There are 2 answers

0
DFriend On

Try changing the name of the application file to main.go

If that fixes it, then the problem is that you need initialize a module named "variables".

In the terminal run

$ go mod init your/path/to/vanillia

Then change the app file name back to variables.go

Until you get to more complicated apps you don't necessarily need to init a modules for your code. But then the app file must be main.go

Read more about code organization here.

0
NutellaTN On

You should run this command

go run main.go

since in go that's the only entrypoint to your application. the package should be named main as you did there as well.