Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
704 views
in Technique[技术] by (71.8m points)

configuration - How to config a simple Go project

I'm trying to follow the Writing an intepreter in Go book, by Thorsten Ball, and in the first chapter he establish this simple scheme

file /Users/myuser/projects/monkey/token/token.go
file /Users/myuser/projects/monkey/lexer/lexer.go
file /Users/myuser/projects/monkey/lexer/lexer_test.go

In lexer/lexer.go and lexer/lexer_test.g the files start as

package lexer

And in lexer_test.go the imports are

import (
    "testing"
    "monkey/token"
)

Then he says that for running the test, I have to run (from /Users/myuser/projects/monkey directory):

go test lexer/lexer_test.go

But when I do this, I receive the error:

lexer/lexer_test.go:6:2: cannot find package "monkey/token" in any of:
    /usr/local/opt/go/libexec/src/monkey/token (from $GOROOT)
    /Users/myuser/golang/src/monkey/token (from $GOPATH)
FAIL    command-line-arguments [setup failed]
FAIL

I've been trying to understand how to configure the packages in go, but I found a lot of very complicated documentation about GOPATH, GOROOT and go.mod. I've been trying all this approach without get rid of the issue.

Can someone help me please? I'm sure is a simple fix but I cannot figure it out :(

question from:https://stackoverflow.com/questions/65871966/how-to-config-a-simple-go-project

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As the error message says, the compiler couldn't find the package locally.

Are you sure you have installed the package?

You may need to do go get [packagename]

For e.g., go get golang.org/x/tools/cmd/goimports


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...