如何分析哪個源文件導致“不允許導入周期”問題?錯誤消息不夠清晰,無法讓我解決問題:package command-line-arguments imports app.exap/i8/internal imports app.exap/i8/internal/data/retrieves imports app.exap/i8/internal/integration/datastore imports app.exap/i8/internal/objects/modules imports app.exap/i8/internal/data imports app.exap/i8/internal/integration/datastore: import cycle not allowedpackage command-line-arguments imports app.exap/i8/internal imports app.exap/i8/internal/data/retrieves imports app.exap/i8/internal/integration/datastore imports app.exap/i8/internal/objects/modules imports app.exap/i8/internal/data imports app.exap/i8/internal/objects/modules: import cycle not allowed
1 回答

30秒到達戰(zhàn)場
TA貢獻1828條經(jīng)驗 獲得超6個贊
這個問題不能歸咎于單個源文件,僅僅是因為導入周期通常涉及來自不同包的多個源文件。
但是,您可以從錯誤消息中收集有價值的信息:您的項目似乎遭受了兩個不同的導入周期(2周期和3周期)的影響,涉及三個包:
要打破這些循環(huán),首先需要確定應消除循環(huán)的哪些邊。但是,我很難就此為您提供明確的指導,因為要消除的最佳邊緣高度依賴于項目的上下文。
但是,避免 Go 中導入周期的一個很好的經(jīng)驗法則是,高級包不應依賴于較低級別的包。因此,您很可能不想依賴app.exap/i8/internal/data
也
app.exap/i8/internal/integration/datastore
或。
app.exap/i8/internal/objects/modules
一旦你決定了要消除哪兩個邊緣,只需確定導入包的哪些源文件包含違規(guī)的導入聲明,并找到一種方法來重構代碼以刪除它們。
- 1 回答
- 0 關注
- 59 瀏覽
添加回答
舉報
0/150
提交
取消