package main import ( "encoding/xml" "io/ioutil" "os" ) func processXML(message *LogMessage) { // queue for read xml (limit number of parallel read files) defer wg.Done() queueForConcurrent <- struct{}{} defer func() { <-queueForConcurrent }() message.xml.isWellFormed = ParseXml(message.path) writeLog(message) return } func IsValidXML(data []byte) bool { return xml.Unmarshal(data, new(interface{})) == nil } func ParseXml(xml_path string) bool { xmlFile, err := os.Open(xml_path) if err != nil { return false } // defer the closing of our xmlFile so that we can parse it later on defer xmlFile.Close() // read our opened xmlFile1 as a byte array. here I am checking if the file is valid or not byteValue, err := ioutil.ReadAll(xmlFile) if err != nil { return false } if !IsValidXML(byteValue) { return false } return true }