英文:
GoLang set library (golang-set) not compiling
问题
我正在使用这个集合库 golang-set。当我尝试创建一个集合时,我遇到了以下错误:
invalid operation: cannot index mapset.NewSet (value of type func(s ...interface{}) mapset.Set)
以下是完整的代码:
package main
import (
mapset "github.com/deckarep/golang-set"
)
func main() {
mySet := mapset.NewSet[string]()
}
我在Ubuntu上使用的是go版本1.18.2,代码与文档中的完全一样。
英文:
I was using this set library golang-set. I get the following error when trying to create a set:
invalid operation: cannot index mapset.NewSet (value of type func(s ...interface{}) mapset.Set)
Here is the full code
package main
import (
mapset "github.com/deckarep/golang-set"
)
func main() {
mySet := mapset.NewSet[string]()
}
I'm using go version 1.18.2 on Ubuntu, the code is exactly how it appears on the documentation.
答案1
得分: 2
根据Joachim Isaksson的指示,应该将其导入为:
import (
mapset "github.com/deckarep/golang-set/v2"
)
同时在go.mod文件中,版本应该是2xx,目前版本为2.1.0:
require github.com/deckarep/golang-set/v2 v2.1.0
英文:
As Joachim Isaksson noted, it should be imported as
import (
mapset "github.com/deckarep/golang-set/v2"
)
also in go.mod the version should be 2xx, as of now it is at 2.1.0
require github.com/deckarep/golang-set/v2 v2.1.0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论