Skip to content

Commit

Permalink
Add comment for MarshalXML in config template
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianczech committed Mar 26, 2024
1 parent ae0300f commit 2544a4b
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions templates/sdk/config.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -144,32 +144,31 @@
}
{{- end}}

// MarshalXML customized implementation of XML marshal due to requirement to skip
<system> as root for configuration settings
func (c configXml) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
{{- range $_, $param := $.Spec.Params}}
if c.{{$param.Name.CamelCase}} != nil {
start.Name = xml.Name{Local: "{{xmlName $param}}"}
if err := e.EncodeElement(c.{{$param.Name.CamelCase}}, start); err != nil {
return err
}
}
{{- end}}
{{- range $_, $param := $.Spec.OneOf}}
if c.{{$param.Name.CamelCase}} != nil {
start.Name = xml.Name{Local: "{{xmlName $param}}"}
if err := e.EncodeElement(c.{{$param.Name.CamelCase}}, start); err != nil {
return err
}
}
{{- end}}

for _, v := range c.Misc {
if err := e.Encode(v); err != nil {
// MarshalXML customized implementation of XML marshal due to requirement to skip 'system' as root for configuration settings
func (c configXml) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
{{- range $_, $param := $.Spec.Params}}
if c.{{$param.Name.CamelCase}} != nil {
start.Name = xml.Name{Local: "{{xmlName $param}}"}
if err := e.EncodeElement(c.{{$param.Name.CamelCase}}, start); err != nil {
return err
}
}

return nil
{{- end}}
{{- range $_, $param := $.Spec.OneOf}}
if c.{{$param.Name.CamelCase}} != nil {
start.Name = xml.Name{Local: "{{xmlName $param}}"}
if err := e.EncodeElement(c.{{$param.Name.CamelCase}}, start); err != nil {
return err
}
}
{{- end}}

for _, v := range c.Misc {
if err := e.Encode(v); err != nil {
return err
}
}

return nil
}
{{- end}}

0 comments on commit 2544a4b

Please sign in to comment.