{"id":114,"date":"2021-02-22T11:42:11","date_gmt":"2021-02-22T19:42:11","guid":{"rendered":"http:\/\/iaastalk.com\/?p=114"},"modified":"2021-02-22T11:42:11","modified_gmt":"2021-02-22T19:42:11","slug":"cyclic-dependency-in-golang","status":"publish","type":"post","link":"http:\/\/iaastalk.com\/?p=114","title":{"rendered":"Cyclic Dependency in Golang"},"content":{"rendered":"\n<p>Example:<\/p>\n\n\n\n<p>A import B<\/p>\n\n\n\n<p>B import A<\/p>\n\n\n\n<p>X import A or B<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Solution?<\/p>\n\n\n\n<p>Abstract common things into an interface &#8220;I&#8221;.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Move I into it&#8217;s own package.<\/p>\n\n\n\n<p>i.I<\/p>\n\n\n\n<p>A return i.I<\/p>\n\n\n\n<p>B import A &amp; i.I, B create a implementation of i.I and set it on A<\/p>\n\n\n\n<p>A &lt;- B (so B only depends on B and I.i , A does not depend on B)<\/p>\n\n\n\n<p>X ask A to return B<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Example: A import B B import A X import A or B Solution? Abstract common things into an interface &#8220;I&#8221;. Move I into it&#8217;s own package. i.I A return i.I B import A &amp; i.I, B create a implementation of i.I and set it on A A &lt;- B (so B only depends on B [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/posts\/114"}],"collection":[{"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/iaastalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=114"}],"version-history":[{"count":1,"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":115,"href":"http:\/\/iaastalk.com\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions\/115"}],"wp:attachment":[{"href":"http:\/\/iaastalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iaastalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iaastalk.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}