Skip to content

Instantly share code, notes, and snippets.

@mgenov
Created October 27, 2017 10:56
Show Gist options
  • Save mgenov/90c9ab1b80d58dd5779cacd6f95c1d45 to your computer and use it in GitHub Desktop.
Save mgenov/90c9ab1b80d58dd5779cacd6f95c1d45 to your computer and use it in GitHub Desktop.
func marshalChannel(fileName string, channel *outputChannel) error {
f, err := os.Create(fileName)
if err != nil {
return fmt.Errorf("unable to open output file due: %v", err)
}
defer f.Close()
tmp := struct {
outputChannel
XMLName struct{} `xml:"channel"`
}{outputChannel: *channel}
b := &bytes.Buffer{}
enc := xml.NewEncoder(b)
enc.Indent(" ", " ")
b.Write([]byte(xml.Header))
if err := enc.Encode(tmp); err != nil {
return fmt.Errorf("unable to marshall content due: %v", err)
}
content := string(b.Bytes())
content = html.UnescapeString(content)
fmt.Printf("content: %s\n", content)
f.Write([]byte(content))
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment