GoLang set library (golang-set) not compiling

Issue

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.

Solution

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

Answered By – Sennay Wgt

Answer Checked By – Marilyn (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.