'how to make a function to return a generic of struct?

I'm learning genric in go. I have struct User and Member, and I want to make a function to return User or Member. How I can achieve this?

edit: I don't want to use interface{} or any



Solution 1:[1]

interface{} has always been an eyesore in Go - so Go 1.18 (with Generics support) you can now use the new keyword any for any type:

func myFunc[T any](in T) (out T) {
    // do stuff
    return
}

or you can use a targeted subset of types as @icza outlines User | Member

https://go.dev/play/p/RGm6cl4ncqA?v=gotip

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 colm.anseo