Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.12.1 darwin/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/Users/mj/Library/Caches/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin" GOPATH="/Users/mj/go" GOPROXY="https://goproxy.io" GORACE="" GOROOT="/usr/local/Cellar/go/1.12.1/libexec" GOTMPDIR="" GOTOOLDIR="/usr/local/Cellar/go/1.12.1/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xb/dsd0_2b92x7bsl92xlzj6fbm0000gn/T/go-build222988675=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
What did you expect to see?
What did you see instead?
What i want to do ?
i want to RegisterViewPath in sub project, see this link
admin.RegisterViewPath("github.com/qor/admin/views")
this works when i don't use go mod (only go get in project root)
but if i use go.mod, when i run go run main.go
in qor-example(import qor/admin)
i will get panic error,
2019/06/02 13:03:26 "GET http://localhost:7000/admin HTTP/1.1" from [::1]:57001 - panic: runtime error: invalid memory address or nil pointer dereference
because templates can't be found.
i know go mod is stored in $GOPATH/pkg/github.com/qor/admin@<hash_version>
, how can i get that path in code ?
and how do i the project is running in go mod mode, because i don't want to break that.
in short, i want to add mod support like this
if (RUNNING_IN_GO_MOD_MODE) {
admin.RegisterViewPath("$GOPATH/pkg/mod/github.com/qor/admin@<hash_version>/views")
} else {
admin.RegisterViewPath("github.com/qor/admin/views")
}