Golang Copy all struct function to another struct newly created and also the fields

Viewed 31
type Old struct {
    Gender int
    From   string
    To     string
     Id    string
}


 func (o *Old ) CheckGender()int{
   return o.Gender
}
type New struct {
    Id    string
    Name  string
   
}
func (n *New) CheckName()string{
       return n.Name
    }

Now i need to create new struct that has both New and Old Values

the struct could be this below and if a value exist in one the once it inherits it just uses only one just like the id in the field. and also uses the functions

    type NewAndOld struct {
        Gender int
        From   string
        To     string
        Id    string
        Name  string
    }

     func (n *NewAndOld ) CheckGender()int{
       return n.Gender
    }
    func (n *NewAndOld ) CheckName()string{
       return n.Name
    }
0 Answers
Related