I have two separate packages, in which the struct implements the same functions. In fact, most of the function's code are also identical For e.g.
package #1
type T1 struct {
Message string
ID string
}
func (t *T1) GetID() {
return t.ID
}
func (t *T1) GetRedisID() {
return "t1" // hardcoded
}
package #2
type T2 struct {
ClassName string
ID string
}
func (t *T2) GetID() {
return t.ID
}
func (t *T2) GetRedisID() {
return "t2" // hardcoded
}
I would like to keep the functions common between these two packages. What would be the options to do this in Go.
I cannot use interfaces here, because I want to access the variables also within the structure and keep the function common. I do not want to reimplement the function in both the files.