goland多檔案編程時,提示找不到主模塊 。
這種情況需要怎么弄才能實作多檔案編程呢
三個檔案里的代碼如下:
main.go:
package main
//定義介面
type inter interface {
//通信介面
CSocketProtocol()
//加密介面
CEncDesProtocol()
}
//多型實作
func framework(i inter) {
i.CSocketProtocol()
i.CEncDesProtocol()
}
func main() {
cs1 := CSckImp1{"廠商1的加密資料", "廠商1的通信資料"}
framework(&cs1)
cs2 := CSckImp2{"廠商2的加密資料", "廠商2的通信資料", 55}
framework(&cs2)
}
廠商1.go:
package main
import "fmt"
//廠商 1 類
type CSckImp1 struct {
data string
socket string
}
func (cs1 *CSckImp1) CSocketProtocol() {
fmt.Printf("廠商1 的通信介面資料為:%s\n", cs1.socket)
}
func (cs1 *CSckImp1) CEncDesProtocol() {
fmt.Printf("廠商1 的加密介面資料為:%s\n", cs1.data)
}
廠商2.go :
package main
import "fmt"
//廠商2 類
type CSckImp2 struct {
data string
socket string
value int
}
func (cs2 *CSckImp2) CSocketProtocol() {
fmt.Printf("廠商2 的通信介面資料為:%s\n", cs2.socket)
}
func (cs2 *CSckImp2) CEncDesProtocol() {
fmt.Printf("廠商2 的加密介面資料為:%s 數值為:%d\n", cs2.data, cs2.value)
}
列印結果:go: cannot find main module; see 'go help modules'
這種情況該怎么辦呢?在線等
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/238759.html
標籤:go語言
上一篇:用openpyxl寫入到已經編輯好條件格式的EXCEL,
下一篇:關于匯編的小問題
