golang undefined module, which is downloaded correctly

huangapple go评论116阅读模式
英文:

golang undefined module, which is downloaded correctly

问题

我按照kafka go示例项目上的说明进行操作。在使用以下命令获取模块后:

go get github.com/confluentinc/confluent-kafka-go/kafka

它出现在我的用户目录中:

C:\Users\fjod\go\pkg\mod\github.com\confluentinc\confluent-kafka-go@v1.9.2

go.mod文件的内容如下:

module kafka-go-producer

go 1.20

require github.com/confluentinc/confluent-kafka-go v1.9.2

当我输入go list命令时,只看到我的模块:

go list                                                                                                                  
kafka-go-producer

项目结构如下:

dir                                                                                                                      

目录:F:\work\kafka\kafka_dotnet_golang\src\golang\kafka-go-producer

模式                最后写入时间         长度 名称
----                -------------         ------ ----
d-----       07.06.2023     11:27                  .idea
-a----       07.06.2023     11:41             93   go.mod
-a----       07.06.2023     11:22          21054   go.sum
-a----       07.06.2023     11:05           1463   producer.go
-a----       07.06.2023     10:43             32   producer.properties
-a----       07.06.2023     10:39            932   util.go

当我输入go build命令时,出现以下错误:

go build                                                                                                                 
# kafka-go-producer
.\util.go:12:42: undefined: kafka.ConfigMap
.\util.go:14:32: undefined: kafka.ConfigValue
.\producer.go:21:18: undefined: kafka.NewProducer
.\producer.go:50:20: undefined: kafka.Message
.\producer.go:51:26: undefined: kafka.TopicPartition
.\producer.go:51:73: undefined: kafka.PartitionAny

GoLand正确识别了这个依赖项,并且没有报告任何错误。但是构建不起作用。

我的go env输出如下:

go env                                                                                                                  
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\fjod\AppData\Local\go-build
set GOENV=C:\Users\fjod\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\fjod\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\fjod\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.20.5
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=F:\work\kafka\kafka_dotnet_golang\src\golang\kafka-go-producer\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\fjod\AppData\Local\Temp\go-build3429863524=/tmp/go-build -gno-record-gcc-switches

我尝试重新安装go,并从头开始按照教程操作了3次。无论我尝试什么,我从来没有在go list输出中看到github.com/confluentinc/confluent-kafka-go/kafka

编辑1:我尝试使用这个示例来检查是否可以使用模块,使用github.com/google/uuid模块的简单程序正常工作。看起来这是与kafka相关的问题:/

英文:

I follow instructions on kafka go sample project. After I get module using command

go get github.com/confluentinc/confluent-kafka-go/kafka

it appears inside my user directory:

C:\Users\fjod\go\pkg\mod\github.com\confluentinc\confluent-kafka-go@v1.9.2

Contents of go.mod file:

module kafka-go-producer

go 1.20

require github.com/confluentinc/confluent-kafka-go v1.9.2

When I enter go list, I see only my module:

go list                                                                                                                  ﳑ in powershell at 11:50:56
kafka-go-producer

Project structure:

 dir                                                                                                                      ﳑ in powershell at 12:04:11


    Directory: F:\work\kafka\kafka_dotnet_golang\src\golang\kafka-go-producer


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       07.06.2023     11:27                  .idea
-a----       07.06.2023     11:41             93   go.mod
-a----       07.06.2023     11:22          21054   go.sum
-a----       07.06.2023     11:05           1463   producer.go
-a----       07.06.2023     10:43             32   producer.properties
-a----       07.06.2023     10:39            932   util.go

On entering go build command, I see following errors:

go build                                                                                                                 ﳑ in powershell at 11:51:05
# kafka-go-producer
.\util.go:12:42: undefined: kafka.ConfigMap
.\util.go:14:32: undefined: kafka.ConfigValue
.\producer.go:21:18: undefined: kafka.NewProducer
.\producer.go:50:20: undefined: kafka.Message
.\producer.go:51:26: undefined: kafka.TopicPartition
.\producer.go:51:73: undefined: kafka.PartitionAny

GoLand correctly sees this dependency and does not report any errors. But build does not work.

My go env output:

go env                                                                                                                   ﳑ in powershell at 11:51:17
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\fjod\AppData\Local\go-build
set GOENV=C:\Users\fjod\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\fjod\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\fjod\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.20.5
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=F:\work\kafka\kafka_dotnet_golang\src\golang\kafka-go-producer\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\fjod\AppData\Local\Temp\go-build3429863524=/tmp/go-build -gno-record-gcc-switches

I tried reinstalling go and followed tutorial from scratch 3 times. No matter what I try, I have never seen github.com/confluentinc/confluent-kafka-go/kafka in my go list output.

EDIT1: I tried using this example to check if I can use modules at all, and simple program with github.com/google/uuid module works fine. Looks like it's kafka-related problem :/

答案1

得分: 2

看起来现在根本不起作用:
https://github.com/confluentinc/confluent-kafka-go/issues/889

https://github.com/confluentinc/confluent-kafka-go/issues/128

最后,我在WSL中创建了一个项目并继续学习。

英文:

Looks like it should now work at all :
https://github.com/confluentinc/confluent-kafka-go/issues/889

https://github.com/confluentinc/confluent-kafka-go/issues/128

In the end, I created a project in WSL and continued studying.

huangapple
  • 本文由 发表于 2023年6月7日 17:10:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76421657.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定