Golang Set库(Golang-Set)未编译

发布于 2025-02-03 03:09:16 字数 480 浏览 2 评论 0原文

我正在使用此集库 golang-set 。尝试创建一个集合时,我会收到以下错误:

invalid operation: cannot index mapset.NewSet (value of type func(s ...interface{}) mapset.Set)

这是我使用的GO版本1.18.2在Ubuntu上的完整代码

package main

import (
    mapset "github.com/deckarep/golang-set"
)

func main() {
    mySet := mapset.NewSet[string]()

}

,该代码正是文档中它显示的方式。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救赎№ 2025-02-10 03:09:16

正如约阿希姆·伊萨克森(Joachim Isaksson)指出的那样,应该和

import (
    mapset "github.com/deckarep/golang-set/v2"
)

GO中的进口。版本应该为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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文