diff --git a/cmd/goimports/goimports.go b/cmd/goimports/goimports.go index a476a7f3c3..2cca292359 100644 --- a/cmd/goimports/goimports.go +++ b/cmd/goimports/goimports.go @@ -45,8 +45,12 @@ var ( Fragment: true, // This environment, and its caches, will be reused for the whole run. Env: &imports.ProcessEnv{ - GOPATH: build.Default.GOPATH, - GOROOT: build.Default.GOROOT, + GOPATH: build.Default.GOPATH, + GOROOT: build.Default.GOROOT, + GOFLAGS: os.Getenv("GOFLAGS"), + GO111MODULE: os.Getenv("GO111MODULE"), + GOPROXY: os.Getenv("GOPROXY"), + GOSUMDB: os.Getenv("GOSUMDB"), }, } exitCode = 0 diff --git a/imports/forward.go b/imports/forward.go index eef25969de..b4f4287679 100644 --- a/imports/forward.go +++ b/imports/forward.go @@ -4,6 +4,7 @@ package imports // import "golang.org/x/tools/imports" import ( "go/build" + "os" intimp "golang.org/x/tools/internal/imports" ) @@ -42,6 +43,10 @@ func Process(filename string, src []byte, opt *Options) ([]byte, error) { Env: &intimp.ProcessEnv{ GOPATH: build.Default.GOPATH, GOROOT: build.Default.GOROOT, + GOFLAGS: os.Getenv("GOFLAGS"), + GO111MODULE: os.Getenv("GO111MODULE"), + GOPROXY: os.Getenv("GOPROXY"), + GOSUMDB: os.Getenv("GOSUMDB"), Debug: Debug, LocalPrefix: LocalPrefix, }, diff --git a/internal/imports/imports.go b/internal/imports/imports.go index e066d909e4..b5c9754953 100644 --- a/internal/imports/imports.go +++ b/internal/imports/imports.go @@ -21,6 +21,7 @@ import ( "io" "io/ioutil" "log" + "os" "regexp" "strconv" "strings" @@ -145,8 +146,12 @@ func initialize(filename string, src []byte, opt *Options) ([]byte, *Options, er // Set the env if the user has not provided it. if opt.Env == nil { opt.Env = &ProcessEnv{ - GOPATH: build.Default.GOPATH, - GOROOT: build.Default.GOROOT, + GOPATH: build.Default.GOPATH, + GOROOT: build.Default.GOROOT, + GOFLAGS: os.Getenv("GOFLAGS"), + GO111MODULE: os.Getenv("GO111MODULE"), + GOPROXY: os.Getenv("GOPROXY"), + GOSUMDB: os.Getenv("GOSUMDB"), } }