Пример #1
0
func auditIt(a audit.Audit, in string) error {
	inFile, err := os.Open(in)
	if err != nil {
		return err
	}
	defer inFile.Close()

	return a.Add(inFile)
}
Пример #2
0
func main() {
	flag.Parse()
	if *fixIn == *auditIn {
		log.Fatal("Invalid argument: must give a -fix FILE or -audit FILE argument")
	}
	if len(*fixIn) > 0 {
		ffi, err := os.Stat(*fixIn)
		if err != nil {
			log.Fatal("Error opening input file %s: %v", *fixIn, err)
		}
		if ffi.IsDir() {
			if len(*outdir) < 1 {
				log.Fatal("If -fix PATH is a directory, must supply an -outdir PATH")
			}
			err = walkFix(*fixIn, *outdir)
			if err != nil {
				log.Fatalf("Error fixing xml: %v", err)
			}
		} else {
			out := new(bytes.Buffer)
			err = fixIt(*fixIn, out)
			if err != nil {
				log.Fatalf("Error fixing xml: %v", err)
			}
			fmt.Print(out)
		}
		return
	}
	var a audit.Audit
	if len(*tagsIn) > 0 {
		tags := strings.Split(*tagsIn, ",")
		a = audit.NewTagAudit(tags...)
	} else {
		a = make(audit.XMLAudit)
	}
	afi, err := os.Stat(*auditIn)
	if err != nil {
		log.Fatal("Error opening input file %s: %v", *auditIn, err)
	}
	if afi.IsDir() {
		err = walkAudit(a, *auditIn)
	} else {
		err = auditIt(a, *auditIn)
	}
	if err != nil {
		log.Fatalf("Error auditing xml: %v", err)
	}
	if *html {
		fmt.Print(a.Html())
		return
	}
	fmt.Print(a)
}