Monthly Archives: February 2021

Cyclic Dependency in Golang

Example:

A import B

B import A

X import A or B

Solution?

Abstract common things into an interface “I”.

Move I into it’s own package.

i.I

A return i.I

B import A & i.I, B create a implementation of i.I and set it on A

A <- B (so B only depends on B and I.i , A does not depend on B)

X ask A to return B