package main import ( "encoding/json" "encoding/xml" "fmt" "os" "testing" ) func TestMarshallXML(t *testing.T) { s := []Scrobble{ Scrobble{Artist: Correctable{Name: "Led Zeppelin"}, TrackName: Correctable{Name: "Loser"}, Time: 1479682785, Album: Correctable{Name: "Mellow Gold"}}, } fmt.Printf("%v\n", s) scrobbles := Scrobbles{Scrobbles: s, Attrs: Attrs{1, 0}} output, err := xml.MarshalIndent(scrobbles, " ", " ") if err != nil { fmt.Printf("error: %v\n", err) } os.Stdout.Write(output) } func TestMarshallJSON(t *testing.T) { s := []Scrobble{ Scrobble{Artist: Correctable{Name: "Mumford & Sons"}, Time: 1479682537, Album: Correctable{Name: "Sign No More"}, TrackName: Correctable{Name: "Little Lion Man"}}, } scrobbles := Scrobbles{Scrobbles: s, Attrs: Attrs{1, 0}} jsonscrobble := map[string]Scrobbles{"scrobbles": scrobbles} output, err := json.MarshalIndent(jsonscrobble, " ", " ") if err != nil { fmt.Printf("error: %v\n", err) } os.Stdout.Write(output) }