I'm simply trying to import a function from another file

Sorry if this question is too basic. I just started learning Go yesterday

I’m trying to import a function from another file but I get a console error saying the function is undefined. Cant figure out what I’m doing wrong.

I pushed it to my github repo for easy viewing : alkapwn3d/vending-machine-go

go run vending-machine.go” will only compile that one file. Whereas “go run .” will compile and run all of the .go source files in the directory.

go help run

Run compiles and runs the named main Go package.
Typically the package is specified as a list of .go source files from a single
directory, but it may also be an import path, file system path, or pattern
matching a single known package, as in ‘go run .’ or ‘go run my/cmd’.

Duh. I should have known, but that makes sense.
Many thanks kind sir.

  • Save this file in the same directory as the file where you want to use the function(s). If it’s in a different directory, you’ll need to adjust the import path accordingly.