Thanks.

Yes, I always have GO111MODULE=on, hence the difference.

On Mon, 2019-12-09 at 10:04 +0000, Paul Jolly wrote:
> > 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/aef097cd5f48edfdfb3fbeb552f7f1377b31777d.camel%40kortschak.io.

Reply via email to