Skip to content
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

Module tutorial doesn't work for Go 1.16 #44457

Closed
ValleZ opened this issue Feb 20, 2021 · 7 comments
Closed

Module tutorial doesn't work for Go 1.16 #44457

ValleZ opened this issue Feb 20, 2021 · 7 comments

Comments

@ValleZ
Copy link

ValleZ commented Feb 20, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16 windows/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
set GO111MODULE=                                                                                                                                                                                                                                                                          set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Valle\AppData\Local\go-build
set GOENV=C:\Users\Valle\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\Valle\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Valle\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.16
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=                                                                                                                                                                                                                                                                         set CGO_CXXFLAGS=-g -O2                                                                                                                                                                                                                                                                   set CGO_FFLAGS=-g -O2                                                                                                                                                                                                                                                                     set CGO_LDFLAGS=-g -O2                                                                                                                                                                                                                                                                    set PKG_CONFIG=pkg-config                                                                                                                                                                                                                                                                 set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Valle\AppData\Local\Temp\go-build935010229=/tmp/go-build -gno-record-gcc-switches 

What did you do?

I followed steps from https://golang.google.cn/doc/tutorial/call-module-code
I created greetings folder with greetings.go file and run
go mod init example.com/greetings
what created go.mod with

module example.com/greetings

go 1.16

then I created hello folder on the same level, hello.go
with

package main

import (
    "fmt"

    "example.com/greetings"
)

func main() {
    // Get a greeting message and print it.
    message := greetings.Hello("Gladys")
    fmt.Println(message)
}

and go.mod with

module hello

go 1.16

replace example.com/greetings => ../greetings

then I run go build while in the hello folder and get error

hello.go:6:5: cannot find package

(I'm not sure how to run the code from hello folder in play.golang.org, but this mirrors the tutorial files)
https://play.golang.org/p/rtHtLMQHXUO

What did you expect to see?

The tutorial says I should see
go: found example.com/greetings in example.com/greetings v0.0.0-00010101000000-000000000000

What did you see instead?

hello.go:6:5: cannot find package

@fzipp
Copy link
Contributor

fzipp commented Feb 20, 2021

See also #44241 (comment)

@seankhliao
Copy link
Member

Duplicate of #44241

@seankhliao seankhliao marked this as a duplicate of #44241 Feb 20, 2021
@ValleZ
Copy link
Author

ValleZ commented Feb 20, 2021

The linked issue mentions that "go mod tidy" would fix the issue. It does not. Running it in both of the modules as well in parent directory has no effect on any files in these folders.

@fzipp
Copy link
Contributor

fzipp commented Feb 20, 2021

@ValleZ No, the comment says that the user should ignore the "go mod tidy" message (i.e. not run it).

@ValleZ
Copy link
Author

ValleZ commented Feb 20, 2021

Given that "go mod tidy" doesn't do anything I don't really understand how it's a duplicate besides "it fails"

@ValleZ
Copy link
Author

ValleZ commented Feb 20, 2021

The issue that modules do not work and even simplest examples like that fail.

@fzipp
Copy link
Contributor

fzipp commented Feb 20, 2021

@ValleZ Modules work, but the tutorial is broken in multiple ways and must be rewritten to reflect the changes in the module tools workflow with Go 1.16.

@golang golang locked and limited conversation to collaborators Feb 20, 2022
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