package wang/test is not in GOROOT (/usr/local/go/src/wang/test)

若是要用 gopath模式 引入包 從src目錄下開始引入 須要關閉 go mod 模式code

export GO111MODULE=offblog

 

若是使用go mod 模式 it

export GO111MODULE=on class

而且在目錄下執行 go mod init  test

不然就會報錯import

 

package wang/test is not in GOROOT (/usr/local/go/src/wang/test)im

 

 

 

 

 

 

main.goimg

package main

import (
	"wang/test"
	"wang/test/yong"
)
func main()  {
	test.Say()
	yong.Speak()
}

 test.godi

package test

import "fmt"

func Say()  {
	fmt.Println("i am test")
}

 

yong.goco

package yong

import "fmt"

func Speak()  {
	fmt.Println("i am speak")
}
相關文章
相關標籤/搜索