package xvdoc import ( "encoding/json" "fmt" ) type Style struct { JSONMap } func (s *Style) UnmarshalJSON(src []byte) (err error) { //fmt.Println("!!!!!!!UMJ") var m JSONMap if err = json.Unmarshal(src, &m); err == nil { s.JSONMap = m //fmt.Println(s.JSONMap) } return } func (s *Style) mergeStyle(m map[string]Style, rStyle JSONMap, parentName string, level int) (res JSONMap, err error) { if parent, check := m[parentName]; check { var pm JSONMap if pm, err = parent.Result(m, parentName, level+1); err == nil { res = mergeMaps(pm.Map(), rStyle.Map()) } } else { res = rStyle.Copy() } return } func (s *Style) Result(m map[string]Style, childName string, cLevel ...int) (res JSONMap, err error) { //fmt.Println(">>>>>>>>>>>>>>>>>>>>", s, childName, s.JSONMap) level := 0 if len(cLevel) > 0 { level = cLevel[0] } if level >= 100 { return nil, fmt.Errorf("Style loop arrived... (%v)", childName) } res = s.Copy() if s.KeyExists("parent") { if res, err = s.mergeStyle(m, res, s.StringVal("parent", ""), level); err != nil { return } } if s.KeyExists("parents") { for _, pName := range s.StringArray("parents") { if res, err = s.mergeStyle(m, res, pName, level); err != nil { return } } } delete(res, "parent") delete(res, "parents") return }