Cannot use generic type iradix.Tree[T any] without instantiation while installing Go package

Hi everyone,
Can anyone help me with this issue? Any help is APPRECIATED!
I’m trying to access the consul API fully with this package:

“github [slash] github[dot]com/hashicorp/consul/api”

I installed it on my Windows machine and imported it into my Go script, however it seems to have a dependency with this package:

“src[slash] github[dot]com/armon/go-metrics”

Whenever I run the script (which actually should have worked) or run this command “go get -u [github]github[dot]com/armon/go-metrics” to update the version of the package I get this message:

# “src[slash] github[dot]com/armon/go-metrics”
“src[slash] go\src\github[dot]com\armon\go-metrics\start.go:37:17: cannot use generic type iradix.Tree[T any] without instantiation”
“src[slash] go\src\github[dot]com\armon\go-metrics\metrics.go:166:23: cannot infer T (“src[slash]go\src\github[dot]com\hashicorp\go-immutable-radix\iradix.go:32:10”)”

These are my imports:

import (
	"encoding/json"
	"fmt"
	"github[dot]com/go-git/go-git"
	"github[dot]com/go-git/go-git/plumbing/transport/http"
	"github[dot]com/hashicorp/consul/api"
	"github[dot]com/hashicorp/hcl/hclsimple"
)

This is the function where I create an API client (It’s not completed yet!)

func createACLToken(file_name string) {
	// Create a new api.Client object to connect to the Consul server
	client, err := api.NewClient(api.DefaultConfig())
	if err != nil {
		log.Fatal(err)
	}
	// Read the ACL token configuration from the .hcl file
	var token_config api.ACLToken
	err = hclsimple.DecodeFile(fmt.Sprintf("%s.hcl", file_name), nil, &token_config)
	if err != nil {
		log.Fatal(err)
	}
	acl := client.ACL()

	/// Create a new policy with the same name as the ACL token
	policy := api.ACLPolicy{Name: file_name, Rules: token_config.Rules}

	createdPolicy, writeMeta, err := acl.PolicyCreate(&policy, nil)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Policy created: %v\nWriteMeta: %v\n", createdPolicy, writeMeta)

	// // Create a new role with the same name as the ACL token
	// role := api.ACLRole{Name: file_name, Policies: []string{file_name}}
	// _, err = acl.RoleCreate(&role, nil)
	// if err != nil {
	// 	log.Fatal(err)
	// }
}

I also checked these packages in GOPATH directory and they are available:

“…go\src\github[dot]com\armon\go-metrics”
“…go\src\github[dot]com\armon\go-radix”
“…go\src\github[dot]com\hashicorp\consul\api”
“…go\src\github[dot]com\hashicorp\hcl\hclsimple”

Are you using a go module or legacy workspace project?

To me this looks as if you are using incompatible versions of libraries.

I think the library versions are incorrect as Norbert said. It is my understanding that there 2 ways that Go supports upgrading a module to version 2 and beyond: One is to create a “v2” branch for your module in source control (instead of the “master” or “main” branch) and the alternative is to create a “v2” subdirectory within your “master” or “main” branch for your v2 code. It appears that hashicorp did neither and instead only uses tags to identify the version number.

When you run go get, even though your go.mod file requires v1, because github.com/hashicorp/go-immutable-radix v2 (with a generic Tree type) is “mixed” in with v1, you’re getting v2 instead of v1 and therefore get this error.

You could try forking v1 and then go get your own repository instead of hashicorps.

Hi, Thanks for your tips! I actually understood my mistake. I created one module and a custom packages. Now I don’t have that problem any more!!
I have another question regarding my script. I have to automatically generate ACL- Tokens in a Go project via consul API. For that I have this Policy configuration file as an input for creating the token:

	key_prefix "" {
		  policy = "deny"
		}

		key_prefix "apps/app_name_1/" {
		  policy = "list"
		}

		key_prefix "apps/app_name_1/" {
		  policy = "read"
		}

In the requirement that I received, I don’t have to create a policy first before creating a token, but as I understood from the consul API documentation, it is actually needed.
However, the requirement is just to apply this .hcl file in the Go script for creating the token with the given rules and push it to consul. The policy Rules should serve as permissions. This is literally how I got this task, but I don’t understand how to create a Token in this way by just applying the hcl configuration file. Can you give me some example code how it works?