> When you're not in a module it returns /dev/null on linux. I don't > suppose this is platform independent?
I have to say what you saw surprised me until Daniel Martà and I did a bit of experimentation. It seems the value of GO111MODULE matters here. If you have GO111MODULE=on then the result of go mod env outside of a module context is /dev/null (or your system's equivalent) If you have GO111MODULE unset (i.e. auto) then it is empty string. This is certainly not clear to me from the docs in go help environment. I realise that this way (i.e. with the /dev/null output when GO111MODULE=on) you can distinguish between modules being on/off, as well as whether you're in a module context or not (regardless of whether you have modules on/auto). But this doesn't exactly jump out at you from the docs of go help environment, and I for one have incorrectly advised people on how to check "are you in a module context or not". Because the logic becomes something like: if gomod != "" && gomod != os.DevNull { // we are in a module context I'm going to raise an issue to suggest that the docs are clarified here. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CACoUkn4GP287B7E7nMHnBwZsHUzcNS-4Km_x6GX%3DZvoGbbr2PQ%40mail.gmail.com.