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

x/website: tutorial create a module, cannot find package "example.com/greetings" #42871

Closed
reevelau opened this issue Nov 29, 2020 · 5 comments
Closed
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@reevelau
Copy link

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

$ go version
go version go1.15.5 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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/test/Library/Caches/go-build"
GOENV="/Users/test/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/test/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/test/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/opt/go/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
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/tl/cxz4mjv55xl2rdcq1rb8jp280000gn/T/go-build149309703=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I am trying to follow the tutorial to create and reference it in hello.go. The source code of hello.go can be found in the next page, call-module-code.

But when I execute go run hello.go the process failed with error message. To workaround the issue, I need to delete example.com/ before greetings. I double checked the context of the tutorial, there isn't a hint of creating directory structure example.com/greetings but greetings. I don't know whether it was working in the older version of go.

May be creating the structure like this, before creating the go.mod, would smooth the experience of the tutorial

mkdir -p example.com/greetings
cd example.com/greetings

What did you expect to see?

Hi, Gladys. Welcome!

What did you see instead?

hello.go:6:2: cannot find package "example.com/greetings" in any of:
	/usr/local/opt/go/libexec/src/example.com/greetings (from $GOROOT)
	/Users/test/go/src/example.com/greetings (from $GOPATH)
@gopherbot gopherbot added this to the Unreleased milestone Nov 29, 2020
@task4233
Copy link
Contributor

@reevelau
I do not think that you have to create example.com/greetings but greetings.
In my environment, the directory structure was as follows after finishing this page.

$ tree .
.
├── greetings
│   ├── go.mod
│   └── greetings.go
└── hello
    ├── go.mod
    ├── hello
    └── hello.go

2 directories, 5 files 

If you would like to create the directory structure, example.com/greetings, you have to modify go.mod in hello/go.mod as follows.

module hello

go 1.15

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

I hope this helps you.

@ALTree
Copy link
Member

ALTree commented Nov 29, 2020

I agree that the tutorial should work as it is and you shouldn't need to mkdir -p example.com/greetings. My guess is that you missed some of the steps, or did something wrong.

Suggestion: try to re-do the tutorial from scratch. If you still get that error, post your directory structure like @task4233 did above, and the content of all the files; and we may be able to understand what went wrong.

@ALTree ALTree added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 29, 2020
@reevelau
Copy link
Author

I was doing the tutorial in $GOPATH/src making me able to call the greeting module by creating the folder structure. Instead, I should follow the instruction to work on the home directory. Thank you everyone.

@sylviankahane
Copy link

I am trying to follow the tutorial from "https://golang.org/doc/code#Workspaces" and I am getting:

hello.go:6:2: cannot find package

In no place there is a mention that a $GOPATH/src has to be created. What is more I don't find a folder named example.com/user/hello. Where I supposed to be. ?

go version go1.16.5 linux/amd64 in Ubuntu 20

@seankhliao
Copy link
Member

@sylviankahane It doesn't need to exist, you probably missed a step

Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.

For questions please refer to https://github.com/golang/go/wiki/Questions

@golang golang locked and limited conversation to collaborators Jun 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants