Reputation: 11533
Suppose I have a package within a package github.com/user/foo
:
foo/
main.go (package main)
bar/
bar.go (package bar)
Now, within bar.go
I would like to use an exported type from main.go
.
package main
type FooBar struct {}
If I try to import "github.com/user/foo"
I get cycled imports not allowed error. Is there any way to do this, other than to create own repo for bar
, which I don't want.
Upvotes: 2
Views: 7773
Reputation: 99244
You can separate it like:
foo/
main.go (package main)
foo/
foo.go (package foo)
bar/
bar.go (package bar)
then import "path/foo/foo"
in bar.go
Upvotes: 6