我有一系列按使用鏈接但邏輯獨立的 go 檔案。它們都使用在單獨檔案中定義的一組通用幫助函式。
我的目錄結構如下圖所示。
src/
├── foo1.go
├── foo2.go
├── ...
├── fooN.go
└── helper/
└── helper.go
foox.go檔案都是這種形式-
package main
import help "./helper"
// functions and structs that use functionality in
// helper but are not related to anything going on
// in other foox.go files
func 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 檔案,而無需經歷制作數十個模塊的麻煩。
uj5u.com熱心網友回復:
您可以通過設定環境變數來禁用模塊模式GO111MODULE=off
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/524291.html
標籤:去包裹相对路径
