Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoLang set library (golang-set) not compiling

Tags:

go

set

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.

like image 929
Sennay Wgt Avatar asked Oct 30 '25 07:10

Sennay Wgt


1 Answers

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
like image 58
Sennay Wgt Avatar answered Oct 31 '25 20:10

Sennay Wgt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!