I have the following code snippet. type workloadInterface interface { *appsV1.Deployment | *appsV1.StatefulSet }
. . . func (a *adapter) processDepOrSSForSvc(client kubernetes.Interface, ns, svcName, workloadName, svcVersionType string) { switch svcVersionType { case serviceDeployment: dep, err := client.AppsV1().Deployments(ns).Get( context.Background(), workloadName, v1.GetOptions{}) if err != nil { log.Errorf("Deployment fetch failed: %v", err) return } processWorkload[*appsV1.Deployment](dep) // <----- generics call case serviceStatefulSet: ss, err := client.AppsV1().StatefulSets(ns).Get( context.Background(), workloadName, v1.GetOptions{}) if err != nil { log.Errorf("Statefulset fetch failed: %v", err) return } processWorkload[*appsV1.StatefulSet](ss) // <------ generics call . . . func processWorkload[V workloadInterface](w V) { // <----------generic function log.Debugf("Namespace: %s Service: %s Deployment: %s", ns, t.ServiceName, w.Name) <--------- Error here What am I doing wrong ? I am trying to use generics where the object could be either a `Deployment` or `StatefulSet`. If I compile, I get an error like: internal/telegraf-adapter/service-details.go:143:24: w.Name undefined (type V has no field or method Name) internal/telegraf-adapter/service-details.go:144:23: w.Name undefined (type V has no field or method Name) internal/telegraf-adapter/service-details.go:146:11: w.Annotations undefined (type V has no field or method Annotations) Name and Annotations are methods available in both the Deployment and the StatefulSet structs. Thanks. -- Sankar P http://psankar.blogspot.com -- 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 on the web visit https://groups.google.com/d/msgid/golang-nuts/CAMSEaH5%2Bv%3DbTbThB407vnUb_81qRwkon36eCzKW-Q%3DbZ-YgcAg%40mail.gmail.com.