I am trying to import local modules, but I am unable to import it using go mod
. I initially built my project using go mod init github.com/AP/Ch2-GOMS
Note my environment is go1.14
and I am using VSCode as my editor.
This is my folder structure
Ch2-GOMS
│ ├── go.mod
│ ├── handlers
│ │ └── hello.go
│ └── main.go
My main.go
code:
package main
import (
"log"
"net/http"
"os"
"github.com/AP/Ch2-GOMS/handlers" // This gives "could not import github.com/AP/Ch2-GOMS/handlers" lint error
)
func main() {
l := log.New(os.Stdout, "product-api", log.LstdFlags)
hh := handlers.NewHello(l)
sm := http.NewServeMux()
sm.Handle("/", hh)
http.ListenAndServe(":9090", nil)
}
I cannot see auto-complete for my local modules such as handlers.NewHello
.
go build
generated go.mod
contents:
module github.com/AP/Ch2-GOMS
go 1.14
I am also getting You are neither in a module nor in your GOPATH. Please see https://github.com/golang/go/wiki/Modules for information on how to set up your Go project. warning in VScode, even though i have set GO111MODULE=on
in my ~/.bashrc
file
go build
. Stop using IDEs the moment you encounter fundamental problems and fall back to std tooling. – Chemotherapy