#file management imports that probably aren't as complicated as I'll make it out to be
20 messages · Page 1 of 1 (latest)
so lets say
/ -> is the repo root
/go.mod-> is named "foobar"
/cmd1 -> a main module
/cmd2 -> a main module
/cmder -> a module named "cmder"
```cmd1 can import `foobar/cmder`
cmd1 cannot import `foobar/cmd2`
assuming cmd1 is named as main
you cannot do that
/ -> is the repo root
/go.mod-> is named "foobar"
/do1er -> a module named "do1er"
/do1er/cmd-> a module named "main" that uses do1er to do stuff
/cmd2 -> a main module, cant import /do1er/cmd, but can import /do1er
/cmder -> a module named "cmder"
no you cannot do that
you should just refactor your directory instead
that seems even worst off
what's the problem with just refactoring the directories?
first off since the program could only be running in server or client, why does it matter if they interact with the same stuff in code?
for example what about this
instead you just split it out so there's a portion of the struct data that can be interacted with, but stuff in do1er/cmd wont be interactable
does that not fit your needs?
/ -> is the repo root
/go.mod -> is named "foobar"
/client -> a module named "main" is the CLI client
/server -> a module named "main" is the server
/foobar -> a module named "foobar" stores models used by both server and client
basically don't want them to interact in code (instead the cli will end up making requests to api endpoints).
it's impossible forclient's code to alter aserver's state(even global state stored infoobar), since they both are running in different instances
so even if you want to it's impossible
I'm trying to work out how to have a function in a file in one main package be accessible by another file in the same main package
you dont actually need to do anything for this to happen(assuming same main package as in same directory)
unless you meant nested stuff...
yes, go treats all .go in the same directory(not nested) as one, the separation in multiple is just for developer's convivence
(after all would been a mess if everything has to be in 1 file)
hmm ok, mind showing the error then, maybe there's problem with your setup
try go run . to "run with everything in the dir"
seems like go run file.go is taken literally to run only file.go
not really just use go build and run the executable
or go run . (but it's very easy to forget, i had to google to make sure before suggesting it)