ygot
ygot copied to clipboard
How to merge generated go structs from 2 different yang models
Hi,
I have 2 different sets of yang files, which are converted into go structs, both having parent node as Device. But when i tried to merge the go structs using ygot.MergeStructs() API, getting error as cannot merge structs that are not of matching types, *openconfig.Device != *openconfig.Device
For Example:
type Device struct {
abc *Testabc_abc `path:"abc" module:"test-abc"`
}
type Device struct {
xyz *Testxyz_xyz `path:"xyz" module:"test-xyz"`
}
want to merge these 2 ygot structs into single tree, where both abc and xyz are under single Device struct
Is there a way or an API, which can be used to merge 2 generated go structs.
TestCode :
func TestMergeGoStruct(t *testing.T) {
appgs, err := yocapp.LookUpGoStruct("/")
require.Nil(t, err)
tosgs, err := yoc.LookUpGoStruct("/")
require.Nil(t, err)
merged, err := ygot.MergeStructs(tosgs, appgs)
require.Nil(t, err)
t.Logf("merged:%+v", merged)
}
Thanks, Deepak
If you want generated ygot GoStructs to represent two different trees then you would need to generate with both sets of YANG files at the same time.