我有一系列按使用鏈接但在邏輯上獨立的go文件。它們都使用在單獨文件中定義的一組通用輔助函數。我的目錄結構如下圖。src/├── foo1.go├── foo2.go├── ...├── fooN.go└── helper/ └── helper.gofoox.go文件都是這種形式 -package mainimport help "./helper"// functions and structs that use functionality in// helper but are not related to anything going on// in other foox.go filesfunc main() { // more things that uses functionality in helper // but are not related to anything going on in // other foox.go files return}我正在使用 運行特定文件go run foox.go,但最近更新了我的 Go 版本。由于不再允許相對導入,此工作流程現已中斷 -"./helper" is relative, but relative import paths are not supported in module mode構造一個集合獨立的 Go 文件的正確方法是什么,這些文件都依賴于相同的輔助函數集合?所有指南都說要使用模塊,但在這種情況下,這意味著每個 foox.go 文件都有一個單獨的模塊,其中每個文件包含funcs、structs等,永遠不會在任何其他模塊中使用。我想要做的就是能夠運行一個包含另一個本地 .go 文件的單個 .go 文件,而無需經歷制作數十個模塊的麻煩。
- 1 回答
- 0 關注
- 264 瀏覽
添加回答
舉報
0/150
提交
取消