File: example.go

package info (click to toggle)
golang-github-ymomoi-goval-parser 0.0~git20170813.0.0a0be1d-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 6,196 kB
  • sloc: xml: 77,785; makefile: 5
file content (41 lines) | stat: -rw-r--r-- 819 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main

import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
	"os"

	"github.com/k0kubun/pp"
	"github.com/ymomoi/goval-parser/oval"
)

func main() {
	if len(os.Args) < 2 {
		fmt.Printf("usage: %s file1 file2 ...\n", os.Args[0])
		return
	}
	for _, f := range os.Args[1:len(os.Args)] {
		fmt.Print(f + " : ")
		oval, err := readOval(f)
		if err != nil {
			fmt.Println(err.Error())
		}
		pp.Println(oval)
		pp.Println(oval.Definitions.Definitions[0].Debian)
	}
}

// readOval : Read OVAL definitions from file
func readOval(file string) (*oval.Root, error) {
	str, err := ioutil.ReadFile(file)
	if err != nil {
		return nil, fmt.Errorf("Can't open file: %s", err)
	}
	oval := &oval.Root{}
	err = xml.Unmarshal([]byte(str), oval)
	if err != nil {
		return nil, fmt.Errorf("Can't parse XML: %s", err)
	}
	return oval, nil
}