go packages ai_generated true

import cycle not allowed

ID: go/import-cycle-not-allowed

Also available as: JSON · Markdown
92%Fix Rate
94%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
121 active

Root Cause

Go packages have a circular dependency — package A imports B and B imports A.

generic

Workarounds

  1. 95% success Extract shared types/interfaces into a third package imported by both
    Create a types or models package with the shared definitions

    Sources: https://go.dev/doc/effective_go#package-names

  2. 90% success Use interfaces to break the dependency: depend on abstractions, not implementations
    Package A defines an interface; package B implements it

Dead Ends

Common approaches that don't work:

  1. Merging the packages into one 55% fail

    Creates a monolithic package; violates separation of concerns

  2. Using go:linkname to access unexported symbols 90% fail

    Compiler directive abuse; breaks with Go updates

Error Chain

Frequently confused with: