Can someone help with something that should be simple in golang, but I can't find good information on this at all. I have a go project. It's accumulating multiple files, so I dont want all my .go files in one folder. So if I have the following
src/main.go
src/Foo/foo.go
src/Foo/quax.go
src/Bar/bar.go
How can I reference foo.go from main.go ?
I've tried go mod init in Foo folder, but then I can't reference that module from main.go
I get the error could not import module ... not required module provides package
I don't want those sub folders to be independent packages, the .go files in them don't make any sense whatsoever outside this project. I purely want to just tidy it up. I dont get why this isn't really simple ?
You can't even do anything like
import (
"\Foo\foo.go"
)
or
import (
"\Foo"
)
That's an invalid import path...All the examples I'm seeing online are referencing github repos. What if I want to structure it with folders but not put it on a repo on github (or any source control at all) ? Surely referencing files can't be tied to VCS in any way whatsoever.
Tried using go work, but I can't get that to work either.
https://www.golangprograms.com/golang-import-function-from-another-folder.html
argh, I've no idea what I'm doing wrong.
On this project when I try to mimic what they've done above in your link, I still get
main.go:5:2 package vm/vm.go is not in GOROOT (/usr/local/go/src/vm/vm.go)
I don't know why it wants that path. My source is in
~/Source/exfnlang not the folder its moaning about.
and vs code moans about the import with the error
could not import vm/vm.go (no required module provides package "vm/vm.go")
got it finally!