GoLang set库(golang-set)无法编译。

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

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

huangapple
  • 本文由 发表于 2022年5月29日 13:55:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/72421267.html
匿名

发表评论

匿名网友

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

确定