I don't expect this should be very difficult, go-wise, but I haven't written much code with generics yet.
I have an application that can read commits from either github or bitbucket, but each run will either be for bitbucket or github, not both. I have to retrieve the commits for a branch a couple of times, so I have a "commitsCache" that is keyed by the project, repo, and branch. All three of those have analogs in github and bitbucket. For now, I've declared "BitbucketCommit" and "GithubCommit" structs. It's entirely possible I could merge them eventually, but I'll leave them separate for now. I have this declaration: commitsCache = make(map[string][]any) Note the element type of "any", not BitbucketCommit or GIthubCommit. I assume this is correct. I have both a "get" and "store" method. The following is what I have so far for the "get" method: func getFromCommitsCache[T any](project string, repo string, branch string) ([]T, bool) { commitsCacheMutex.RLock() defer commitsCacheMutex.RUnlock() if commits, found := commitsCache[project+"/"+repo+"/"+branch]; found { if v, ok := commits.([]T); ok { // This line. return v, true } } return nil, false } I'm not quite sure what to do here. The line with "this line" has the following compile error: invalid operation: commits (variable of type []any) is not an interface compilerInvalidAssert <https://pkg.go.dev/golang.org/x/tools/internal/typesinternal#InvalidAssert> I'm currently using Go v1.22.6 , although I could certainly upgrade, if there's a good reason to. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/a689e6f4-3381-4525-9bc1-8ecca350ebb1n%40googlegroups.com.