php小編柚子在本文中將為大家介紹如何使用替換指令在本地導入go模組,並使用主資料夾中的供應商目錄。替換指令是Go語言中的強大功能,可讓我們在開發過程中更靈活地引入本機模組,提高程式碼的可維護性和復用性。透過本文的指導,相信大家能夠輕鬆掌握這項技巧,更有效率地進行Go語言開發。接下來,我們一起來看看具體的操作步驟吧!
問題內容
myexporter 是我的本機模組,我使用替換將其匯入到主模組中。我想使用主專案根目錄下的供應商資料夾在 myexporter 中執行測試。
我的專案目錄結構是這樣的
bitbucket.com |__agent |__exporter | |__myexporter | |__factory.go | factory_test.go | go.mod |__runner | |__main.go | main_test.go |__vendor | |__bitbucket.com/agent/exporter/myexporter | |__factory.go |__go.mod
myexporter go.mod 檔案
module bitbucket.com/agent/exporter/myexporter
agent go.mod 檔有
module bitbucket.com/agent require ( bitbucket.com/agent/exporter/myexporter ) replace bitbucket.com/agent/exporter/myexporter => ./exporter/myexporter
我的問題是
- 如果我執行“go test -mod=vendor ./...”,它只會在 main_test 運行中進行測試
- 如果我使用“go test -mod=vendor exporter/myexporter”,我會得到“package exporter/myexporter is not in goroot”
- 如果我執行“go test -mod=vendor bitbucket.com/agent/exporter/myexporter”,則沒有測試檔案
- 如果我切換到exporter/myexporter 目錄,然後使用“go test ./...”運行,它可以工作,但不能“go test -mod=vendor ./...”,因為供應商目錄位於代理程式的根目錄李>
- 如果我執行“go test -mod=vendor ./exporter/myexporter/”,我會得到“主模組 (bitbucket.com/agent) 不包含套件 bitbucket.com/agent/exporter/myexporter”
建置無法存取 go 包,它依賴供應商資料夾,測試也是如此。我不希望在 myexporter 內的另一個供應商資料夾中存在多個相依性副本。有什麼辦法可以使用代理/供應商資料夾在 myexporter 內執行測試嗎?
解決方法
有什麼辦法可以使用代理程式/供應商資料夾在 MyExporter 內執行測試嗎?
沒有。
您必須在 myexporter 所在的位置進行測試。一旦提供,僅提供實際代碼。
唯一可能的就是組合模組。
它實際上可以歸結為:如果您需要以某種方式並行/一致地測試這兩個模組,那麼它們並不是真正具有不同生命週期的兩個不同模組。如果這些是具有不同生命週期的獨立事物,您可以測試第一個,確保它有效並將其供應給第二個。然後測試第二個,包括它對第一個的使用,但不執行第一個測試,因為不再需要它。
以上是測試使用替換指令匯入的本機 go 模組並使用主資料夾中的供應商目錄的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Go的"strings"包提供了豐富的功能,使字符串操作高效且簡單。 1)使用strings.Contains()檢查子串。 2)strings.Split()可用於解析數據,但需謹慎使用以避免性能問題。 3)strings.Join()適用於格式化字符串,但對小數據集,循環使用 =更有效。 4)對於大字符串,使用strings.Builder構建字符串更高效。

Go語言使用"strings"包進行字符串操作。 1)拼接字符串使用strings.Join函數。 2)查找子串使用strings.Contains函數。 3)替換字符串使用strings.Replace函數,這些函數高效且易用,適用於各種字符串處理任務。

資助bytespackageingoisesential foreffited byteSemanipulation,uperingFunctionsLikeContains,index,andReplaceForsearchingangingAndModifyingBinaryData.itenHancesperformanceNandCoderAceAnibility,MakeitiTavitalToolToolToolToolToolToolToolToolToolForhandLingBinaryData,networkProtocols,networkProtocoLss,networkProtocols,andetFilei

Go語言使用"encoding/binary"包進行二進制編碼與解碼。 1)該包提供binary.Write和binary.Read函數,用於數據的寫入和讀取。 2)需要注意選擇正確的字節序(如BigEndian或LittleEndian)。 3)數據對齊和錯誤處理也是關鍵,確保數據的正確性和性能。

1)usebybytes.joinforconcatenatinges,2)bytes.bufferforincrementalwriting,3)bytes.indexorbytes.indexorbytes.indexbyteforsearching bytes.bytes.readereforrednorederencretingnchunknunknchunknunk.sss.inc.softes.4)

theencoding/binarypackageingoiseforporptimizingBinaryBinaryOperationsDuetoitssupportforendiannessessandefficityDatahandling.toenhancePerformance:1)usebinary.nativeendiandiandiandiandiandiandiandian nessideendian toavoid avoidByteByteswapping.2)

Go的bytes包主要用於高效處理字節切片。 1)使用bytes.Buffer可以高效進行字符串拼接,避免不必要的內存分配。 2)bytes.Equal函數用於快速比較字節切片。 3)bytes.Index、bytes.Split和bytes.ReplaceAll函數可用於搜索和操作字節切片,但需注意性能問題。

字節包提供了多種功能來高效處理字節切片。 1)使用bytes.Contains檢查字節序列。 2)用bytes.Split分割字節切片。 3)通過bytes.Replace替換字節序列。 4)用bytes.Join連接多個字節切片。 5)利用bytes.Buffer構建數據。 6)結合bytes.Map進行錯誤處理和數據驗證。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

SublimeText3漢化版
中文版,非常好用

SublimeText3 Linux新版
SublimeText3 Linux最新版