<commit_before>package common

import (
	"encoding/xml"
	"fmt"
	"os"
	"path"
	"socialapi/config"
)

func XML(i interface{}, fileName string) error {
	header := []byte(xml.Header)
	res, err := xml.Marshal(i)
	if err != nil {
		return err
	}
	// append header to xml file
	res = append(header, res...)

	MustWrite(res, fileName)

	return nil
}

func MustWrite(input []byte, fileName string) {
	wd, err := os.Getwd()
	if err != nil {
		panic(err)
	}

	root := config.Get().Sitemap.XMLRoot
	n := fmt.Sprintf("%s.xml", fileName)
	n = path.Join(wd, root, n)

	output, err := os.Create(n)
	if err != nil {
		panic(err)
	}
	defer func() {
		if err := output.Close(); err != nil {
			panic(err)
		}
	}()
	if _, err := output.Write(input); err != nil {
		panic(err)
	}

}<commit_msg>Sitemap: Breakdown XML into Marshal method<commit_after>package common

import (
	"encoding/xml"
	"fmt"
	"os"
	"path"
	"socialapi/config"
)

func XML(i interface{}, fileName string) error {
	res, err := Marshal(i)
	if err != nil {
		return err
	}

	MustWrite(res, fileName)

	return nil
}

func MustWrite(input []byte, fileName string) {
	wd, err := os.Getwd()
	if err != nil {
		panic(err)
	}

	root := config.Get().Sitemap.XMLRoot
	n := fmt.Sprintf("%s.xml", fileName)
	n = path.Join(wd, root, n)

	output, err := os.Create(n)
	if err != nil {
		panic(err)
	}
	defer func() {
		if err := output.Close(); err != nil {
			panic(err)
		}
	}()
	if _, err := output.Write(input); err != nil {
		panic(err)
	}

}

func Marshal(i interface{}) ([]byte, error) {
	header := []byte(xml.Header)
	res, err := xml.Marshal(i)
	if err != nil {
		return nil, err
	}
	// append header to xml file
	return append(header, res...), nil
}
{'fraction_non_alphanumeric': 0.17612293144208038, 'fraction_numerical': 0.0, 'mean_word_length': 3.318877551020408, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '821685', 'n_tokens_mistral': 679, 'n_tokens_neox': 660, 'n_words': 176}