Home > Software design >  Goland: cannot call specific methods from imported package
Goland: cannot call specific methods from imported package

Time:08-02

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!

CodePudding user response:

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
)
  • Related