package main
import (
"fmt"
"controller/userhandler" //not able to import this custom package
"github.com/gin-gonic/gin"
"net/http"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
func main(){
}
The code below shows that Go is only searching for packages in GOROOT. After not finding controller/userhandler
in GOROOT, ideally, it should look for packages in GOPATH but it does not.
I have already set GOPATH to my workspace path which includes the folders: bin
, src
, and pkg
.
$ go build main.go
main.go:5:2: package controller/userhandler is not in GOROOT (/usr/local/go/src/controller/userhandler)
run go mod init MODULE_NAME
(if the project is outside GOROOT or GOPATH) or just simply go mod init
(if the project is inside GOROOT or GOPATH). The command should be run on the root folder of your project. This would create a go.mod
file that would enable go to resolve your packages.