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

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

Goland: cannot call specific methods from imported package

问题

你好,Gopher们!

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

例如,

bar := progressbar.New(someint)

可以正常工作。

但是如果我调用

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

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

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

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

这是我的go env

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/alex/Library/Caches/go-build"
GOENV="/Users/alex/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/alex/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/alex/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/alex/go/src/awesomeProject/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
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,

bar := progressbar.New(someint)

works perfecly.

But if I call

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

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/alex/Library/Caches/go-build"
GOENV="/Users/alex/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/alex/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/alex/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/alex/go/src/awesomeProject/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
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

以下是翻译好的内容:

"github.com/schollz/progressbar" 与以下源代码和模块文件一起使用。

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

模块文件

	go 1.18

	require github.com/schollz/progressbar/v3 v3.8.7
	require (
	    github.com/mattn/go-runewidth v0.0.13 // indirect
		github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
		github.com/rivo/uniseg v0.3.1 // indirect
		golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
		golang.org/x/sys v0.0.0-20220730100132-1609e554cd39 // indirect
		golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
	)
英文:

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

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

mod file

go 1.18

require github.com/schollz/progressbar/v3 v3.8.7
require (
    github.com/mattn/go-runewidth v0.0.13 // indirect
	github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
	github.com/rivo/uniseg v0.3.1 // indirect
	golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
	golang.org/x/sys v0.0.0-20220730100132-1609e554cd39 // indirect
	golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
)

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:

确定