aboutsummaryrefslogtreecommitdiff
path: root/examples/7-rdfloader/exampleRDFLoader.go
blob: 2e44935acfb0b1f15fcb599b2841dda80627a61a (plain)
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 (
	"fmt"
	"github.com/spdx/tools-golang/rdfloader"
	"os"
	"strings"
)

func getFilePathFromUser() string {
	if len(os.Args) == 1 {
		// user hasn't specified the rdf file path
		panic("kindly provide path of the rdf file to be loaded as a spdx-document while running this file")
	}
	return os.Args[1]
}

func main() {
	// example to use the rdfLoader.
	filePath := getFilePathFromUser()
	file, err := os.Open(filePath)
	if err != nil {
		panic(fmt.Errorf("error opening File: %s", err))
	}

	// loading the spdx-document
	doc, err := rdfloader.Load2_2(file)
	if err != nil {
		fmt.Println(fmt.Errorf("error parsing given spdx document: %s", err))
		os.Exit(1)
	}

	// Printing some of the document Information
	fmt.Println(strings.Repeat("=", 80))
	fmt.Println("Some Attributes of the Document:")
	fmt.Printf("Document Name:         %s\n", doc.CreationInfo.DocumentName)
	fmt.Printf("DataLicense:           %s\n", doc.CreationInfo.DataLicense)
	fmt.Printf("Document NameSpace:    %s\n", doc.CreationInfo.DocumentNamespace)
	fmt.Printf("SPDX Document Version: %s\n", doc.CreationInfo.SPDXVersion)
	fmt.Println(strings.Repeat("=", 80))
}