I have A.go file with a method as follows.
func pInfoEx(reqCtx B.RequestContext) {
fmt.Println(reqCtx.p);
}
For this RequestContext argument in the pInfoEx function I have to import the B.go file which is in another package.
type RequestContext interface {
p() string
}
But B.go imports C.go which inturn imports A.go creating cyclic dependency. How can I go about resolving this cyclic dependency without moving go files to the same package?
I have gone through Cyclic dependencies and interfaces in Golang post, but here the method has an argument which cannot be changed.
One way is to move all data type and interface definitions to separate package, so all will be dependent on it, but the package does not depend on any other. This can be a special package schema
in root folder of the project. Or even top project itself.