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

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

Knowledge map advanced must read: read how large-scale map data efficient storage and retrieval>>>

If you want to use gopath mode to import packages from SRC directory, you need to close gomod mode

export GO111MODULE=off

If you use go mod mode

export GO111MODULE=on

And execute go mod init in the directory

Otherwise, it will report an error

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

main.go

package main

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

test.go

package test

import "fmt"

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

yong.go

package yong

import "fmt"

func Speak()  {
	fmt.Println("i am speak")
}