Created
October 27, 2017 10:56
-
-
Save mgenov/90c9ab1b80d58dd5779cacd6f95c1d45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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