Hi,

I have a use case where there are two different versions of struct. The 
problem is when the model is retrieved from database, it can be of either 
version. Both structs have same getters implemented. 
This is what the code looks like. 

type structA {
   Key1     string
   Key2    string
}

func(s *structA) GetKey1() string {
     return s.key1
}


type structB {
   Key3     string
   Key4    string
}

func(s *structB) GetKey1() string {
     return s.key3
}

version, obj, err := getObjFromDB(args)
if err != nil {
  return err
}

var objA *structA
var objB *structB

if version == "A" {
    objA := obj.(structA)
} else if version == "B" {
    objB := obj.(structB)
}

.... 
I want this logic to be abstracted to one object so that subsequent code 
should like 

obj.GetKey() -> doesn't matter whether obj is of type structA or structB

Any help is greatly appreciated. Thanks for your time to look into this. 





-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to