Skip to content

How to get mod path in code #32384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dfang opened this issue Jun 2, 2019 · 1 comment
Closed

How to get mod path in code #32384

dfang opened this issue Jun 2, 2019 · 1 comment

Comments

@dfang
Copy link

dfang commented Jun 2, 2019

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")
}
@bcmills
Copy link
Contributor

bcmills commented Jun 3, 2019

There is no programmatic way to do this today. See #3035 for a related feature request.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants