Goland:无法从导入的包中调用特定方法。

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

Goland: cannot call specific methods from imported package

问题

你好,Gopher们!

我在GoLand上遇到了一些问题,无论是在Windows还是Mac上。我正在尝试实现这个进度条 "github.com/schollz/progressbar",但是包中并不是所有的方法都起作用。

例如,

  1. bar := progressbar.New(someint)

可以正常工作。

但是如果我调用

  1. bar := progressbar.NewOptions(someint), progressbar.OptionShowBytes(true))

那么编译器会报错,类似于

#./main.go:118:21: undefined: progressbar.NewOptions
#./main.go:118:56: undefined: progressbar.OptionShowBytes

这个包是没问题的。我已经重新导入了几次来进行检查。调整GO111MODULE也没有改变任何东西。

这是我的go env

  1. GO111MODULE="on"
  2. GOARCH="amd64"
  3. GOBIN=""
  4. GOCACHE="/Users/alex/Library/Caches/go-build"
  5. GOENV="/Users/alex/Library/Application Support/go/env"
  6. GOEXE=""
  7. GOEXPERIMENT=""
  8. GOFLAGS=""
  9. GOHOSTARCH="amd64"
  10. GOHOSTOS="darwin"
  11. GOINSECURE=""
  12. GOMODCACHE="/Users/alex/go/pkg/mod"
  13. GONOPROXY=""
  14. GONOSUMDB=""
  15. GOOS="darwin"
  16. GOPATH="/Users/alex/go"
  17. GOPRIVATE=""
  18. GOPROXY="https://proxy.golang.org,direct"
  19. GOROOT="/usr/local/go"
  20. GOSUMDB="sum.golang.org"
  21. GOTMPDIR=""
  22. GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
  23. GOVCS=""
  24. GOVERSION="go1.18.1"
  25. GCCGO="gccgo"
  26. GOAMD64="v1"
  27. AR="ar"
  28. CC="clang"
  29. CXX="clang++"
  30. CGO_ENABLED="1"
  31. GOMOD="/Users/alex/go/src/awesomeProject/go.mod"
  32. GOWORK=""
  33. CGO_CFLAGS="-g -O2"
  34. CGO_CPPFLAGS=""
  35. CGO_CXXFLAGS="-g -O2"
  36. CGO_FFLAGS="-g -O2"
  37. CGO_LDFLAGS="-g -O2"
  38. PKG_CONFIG="pkg-config"
  39. GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lt/86511lks3ns2l0_g7nhl8k840000gn/T/go-build4209101000=/tmp/go-build -gno-record-gcc-switches -fno-common"

在谷歌上搜索这个错误也没有帮助。任何帮助将不胜感激。谢谢!

英文:

Hellо, fellow Gophers!

I have a trouble with import in GoLand, both on Windows and Mac. I am trying to implement this progress bar "github.com/schollz/progressbar", but not all the methods from the package work.

For example,

  1. bar := progressbar.New(someint)

works perfecly.

But if I call

  1. bar := progressbar.NewOptions(someint), progressbar.OptionShowBytes(true))

then the compiler throws errors like

>#./main.go:118:21: undefined: progressbar.NewOptions
>#./main.go:118:56: undefined: progressbar.OptionShowBytes

The package is okay. And I reimported it for a few times just to check. Messing around with GO111MODULE doesn't change anything.

Here is my go env

  1. GO111MODULE="on"
  2. GOARCH="amd64"
  3. GOBIN=""
  4. GOCACHE="/Users/alex/Library/Caches/go-build"
  5. GOENV="/Users/alex/Library/Application Support/go/env"
  6. GOEXE=""
  7. GOEXPERIMENT=""
  8. GOFLAGS=""
  9. GOHOSTARCH="amd64"
  10. GOHOSTOS="darwin"
  11. GOINSECURE=""
  12. GOMODCACHE="/Users/alex/go/pkg/mod"
  13. GONOPROXY=""
  14. GONOSUMDB=""
  15. GOOS="darwin"
  16. GOPATH="/Users/alex/go"
  17. GOPRIVATE=""
  18. GOPROXY="https://proxy.golang.org,direct"
  19. GOROOT="/usr/local/go"
  20. GOSUMDB="sum.golang.org"
  21. GOTMPDIR=""
  22. GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
  23. GOVCS=""
  24. GOVERSION="go1.18.1"
  25. GCCGO="gccgo"
  26. GOAMD64="v1"
  27. AR="ar"
  28. CC="clang"
  29. CXX="clang++"
  30. CGO_ENABLED="1"
  31. GOMOD="/Users/alex/go/src/awesomeProject/go.mod"
  32. GOWORK=""
  33. CGO_CFLAGS="-g -O2"
  34. CGO_CPPFLAGS=""
  35. CGO_CXXFLAGS="-g -O2"
  36. CGO_FFLAGS="-g -O2"
  37. CGO_LDFLAGS="-g -O2"
  38. PKG_CONFIG="pkg-config"
  39. GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lt/86511lks3ns2l0_g7nhl8k840000gn/T/go-build4209101000=/tmp/go-build -gno-record-gcc-switches -fno-common"

Googling the error didn't help either. Any help would be appreciated. Thank you!

答案1

得分: 2

以下是翻译好的内容:

  1. "github.com/schollz/progressbar" 与以下源代码和模块文件一起使用。
  2. bar, _ := progressbar.NewOptions(100), progressbar.OptionShowBytes(true)
  3. 模块文件
  4. go 1.18
  5. require github.com/schollz/progressbar/v3 v3.8.7
  6. require (
  7. github.com/mattn/go-runewidth v0.0.13 // indirect
  8. github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
  9. github.com/rivo/uniseg v0.3.1 // indirect
  10. golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
  11. golang.org/x/sys v0.0.0-20220730100132-1609e554cd39 // indirect
  12. golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
  13. )
英文:

The "github.com/schollz/progressbar" worked with following source and mod file.

  1. bar, _ := progressbar.NewOptions(100), progressbar.OptionShowBytes(true)

mod file

  1. go 1.18
  2. require github.com/schollz/progressbar/v3 v3.8.7
  3. require (
  4. github.com/mattn/go-runewidth v0.0.13 // indirect
  5. github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
  6. github.com/rivo/uniseg v0.3.1 // indirect
  7. golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
  8. golang.org/x/sys v0.0.0-20220730100132-1609e554cd39 // indirect
  9. golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
  10. )

huangapple
  • 本文由 发表于 2022年7月31日 03:56:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/73178660.html
匿名

发表评论

匿名网友

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

确定